Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $post_check = new WP_Query( array(
- // http://codex.wordpress.org/Function_Reference/WP_Query#Custom_Field_Parameters
- 'meta_query' => array(
- array(
- 'key' => 'foobar',
- 'value' => 1,
- ),
- ),
- 'posts_per_page' => 1, // Just checking if it exists, we don't actually need the results
- 'no_found_rows' => true, // We don't care how many total posts match these parameters
- 'update_post_meta_cache' => false, // Don't pre-fetch all custom fields for the results
- 'update_post_term_cache' => false, // Don't pre-fetch all taxonomies for the results
- ) );
- if ( $post_check->have_posts() ) {
- echo 'A post exists with foobar=1';
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement