查询结果未显示,请帮助

时间:2011-08-23 作者:adolfozen

$args = array(

\'post_type\' => \'shows\',

\'operator\' => \'AND\',

\'tax_query\' => array(

             array(
                  \'taxonomy\' => \'location\',
                  \'field\' => \'slug\',
                  \'term\' => \'california\',
                  ),  

             array(    
                  \'taxonomy\' => \'genre\',
                  \'field\' => \'slug\',
                  \'term\' => \'comedy\',   
                  )
    )
);

$my_query = new WP_Query();
$my_query->query($args);

while ( $my_query->have_posts() ) : $my_query->the_post();

echo \'<li>\';
the_title();
echo \'</li>\';

endwhile;

wp_reset_postdata();
我的分类法:

register_taxonomy(\'location\',array (
  0 => \'shows\',
),array( \'hierarchical\' => true, \'label\' => \'location\',\'show_ui\' => true,\'query_var\' => true,\'rewrite\' => array(\'slug\' => \'location\'),\'singular_label\' => \'location\') );

register_taxonomy(\'genre\',array (
  0 => \'shows\',
),array( \'hierarchical\' => true, \'label\' => \'genre\',\'show_ui\' => true,\'query_var\' => true,\'rewrite\' => array(\'slug\' => \'genre\'),\'singular_label\' => \'genre\') );
我的目标是显示带有“前加州”和“喜剧”两个词的帖子,我试图建立这种关系,但遗憾的是没有显示结果

1 个回复
SO网友:Bainternet

在循环中,您只能使用the_title 如果要显示自定义分类法的术语,需要调用它们,最简单的方法是使用get_the_term_list 对于每个分类:

while ( $my_query->have_posts() ) : $my_query->the_post();

echo \'<li>\';
the_title();
echo get_the_term_list( $post->ID, \'location\', \'Location: \', \' \', \'\' );
echo <br/>
echo get_the_term_list( $post->ID, \'genre\', \'Genre: \', \' \', \'\' );
echo \'</li>\';

endwhile;

结束

相关推荐