Last active
May 16, 2016 10:30
-
-
Save harisrozak/7dd1bcba23fd6e5dc1e6 to your computer and use it in GitHub Desktop.
Wordpress :: WP_Query for single
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* by ID */ | |
$args = array( | |
'p' => 42, // id of a page, post, or custom type | |
'post_type' => 'any' | |
); | |
$the_query = new WP_Query($args); | |
/* by post slug */ | |
$args = array( | |
'name' => 'hello-world', // slug of a page, post, or custom type | |
'post_type' => 'any' | |
); | |
$the_query = new WP_Query($args); | |
/* result */ | |
if($the_query->have_posts()) : while( $the_query->have_posts() ) : $the_query->the_post(); | |
the_title(); | |
endwhile; wp_reset_query(); endif; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment