Reputation: 2569
I'm trying to loop over posts on a homepage with the following code:
$args = array ('taxonomy'=>'ad_cat', 'terms'=>'restaurants');
$category_posts = get_posts( $args );
if($category_posts->have_posts()) :
while($category_posts->have_posts()) :
$category_posts->the_post();
the_content() ;
endwhile;
else:
echo "Oops, there are no posts for category ". $cat->term_id .".<br/>";
endif;
but it returns no records (and those records exists).
My question is : how to loop properly over posts?
EDIT:
["taxonomy"]=>
string(6) "ad_cat"
["terms"]=>
array(1) {
[0]=>
string(11) "restaurants"
}
Upvotes: 0
Views: 43
Reputation: 3358
Try with the following code :
$args = array(
'tax_query' => array(
'taxonomy'=>'ad_cat', 'terms'=>'restaurants'
)
)
);
$category_posts = get_posts( $args );
if($category_posts->have_posts()) :
while($category_posts->have_posts()) :
$category_posts->the_post();
the_content() ;
endwhile;
else:
echo "Oops, there are no posts for category ". $cat->term_id .".<br/>";
endif;
Upvotes: 1