Advertisement
Viper007Bond

Untitled

Sep 19th, 2011
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.63 KB | None | 0 0
  1. $post_check = new WP_Query( array(
  2.     // http://codex.wordpress.org/Function_Reference/WP_Query#Custom_Field_Parameters
  3.     'meta_query' => array(
  4.         array(
  5.             'key' => 'foobar',
  6.             'value' => 1,
  7.         ),
  8.     ),
  9.     'posts_per_page' => 1, // Just checking if it exists, we don't actually need the results
  10.     'no_found_rows' => true, // We don't care how many total posts match these parameters
  11.     'update_post_meta_cache' => false, // Don't pre-fetch all custom fields for the results
  12.     'update_post_term_cache' => false, // Don't pre-fetch all taxonomies for the results
  13. ) );
  14.  
  15. if ( $post_check->have_posts() ) {
  16.     echo 'A post exists with foobar=1';
  17. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement