Skip to content

Instantly share code, notes, and snippets.

@harisrozak
Last active May 16, 2016 10:30
Show Gist options
  • Save harisrozak/7dd1bcba23fd6e5dc1e6 to your computer and use it in GitHub Desktop.
Save harisrozak/7dd1bcba23fd6e5dc1e6 to your computer and use it in GitHub Desktop.
Wordpress :: WP_Query for single
<?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