Reputation: 12568
I have a set of fields in my Custom Post Type 'games' taxonomies called 'gamename' - I am trying to retrieve this value using query_posts like so....
$args = array(
'post_status'=>'publish',
'post_type'=>'games',
'gamename' => 'Space Invaders'
);
query_posts($args);
if(have_posts()) : while (have_posts()) : the_post();
the_title();
endwhile; else:
echo 'No Posts!';
endif;
wp_reset_query();
This isnt working for me and it is just returning 'No Posts'
Can some one suggest what I am doing wrong?
Upvotes: 0
Views: 127
Reputation: 13840
First of all, don't use query_posts();
, blech. use $query = new WP_Query
, you can read up on it here.
query_posts()
tries to be the king and overwrites global variables (EW!), the WP_Query
class does not, however, and is considered the best (only?) way you should loop posts.
I personally (and have had colleagues) who have all had the same issue, query_posts()
returning no posts. and 9/10 times, in the end, it's because it's overwriting global variables (namely the $post D:) which makes it return empty. And 9/10 times, using $query = new WP_Query;
instead works!
If you are MARRIED to useing query_posts()
however, try calling wp_reset_query()
BEFORE your code too, maybe you've got a plugin or something that didn't reset it properly before your code initiates
EDIT
you have
if(have_posts()) : while (have_posts()) : the_post();
any reason you have that if statement, and not just the standard:
while ( have_posts() ) : the_post();
Upvotes: 1