2

I think something like this should do the job: $meta_query = array( array( 'key' => 'foo', 'compare' => 'EXISTS', ), ); $args = array( 'meta_query' => $meta_query ); $query = new WP_Query( $args ); if ( $query->have_posts() ) { while ( $query->have_posts() ) { $query->the_post(); $...


1

You can check if the query returned any posts by doing $home_query->have_posts(). $home_query = new WP_Query( array('posts_per_page' => get_query_var('posts_per_page'),'paged' => $current_page ) ); if( !$home_query->have_posts() ){ // Do this if $home_query had no posts. }


Only top voted, non community-wiki answers of a minimum length are eligible