Skip to content

Instantly share code, notes, and snippets.

@mfields
Created February 1, 2013 01:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mfields/4688346 to your computer and use it in GitHub Desktop.
Save mfields/4688346 to your computer and use it in GitHub Desktop.
Illustrate how to check the value of ```post__in``` before it is used to construct a new ```WP_Query``` object.
<?php
$my_posts = false;
$my_post_ids = mytheme_get_special_post_ids();
if ( ! empty( $my_post_ids ) ) {
$my_posts = new WP_Query( array(
'post__in' => $my_post_ids,
'post_status' => 'publish',
'posts_per_page' => 10,
'no_found_rows' => true,
) );
}
if ( $my_posts ) {
// Do something with the posts here.
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment