0

我正在尝试使用以下代码遍历主页上的帖子:

$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"
    }
4

1 回答 1

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;  
于 2013-08-11T16:53:26.437 回答