我正在尝试使用以下代码遍历主页上的帖子:
$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;
但它不返回任何记录(并且存在这些记录)。
我的问题是:如何在帖子上正确循环?
编辑:
["taxonomy"]=>
string(6) "ad_cat"
["terms"]=>
array(1) {
[0]=>
string(11) "restaurants"
}
答案 0 :(得分:1)
尝试使用以下代码:
$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;