我有一个自定义的帖子类型“restaurants”和一个分类法“location”,所以我可以通过URL获取一个位置的餐馆。在一个特定位置(CityA)的分类页面上,我想显示餐厅的所有帖子类型和分类术语“CityA”。然而,Wordpress也在同一个查询中为我提供了分类术语“CityB”或“CityC”的帖子。看看:
$args = array ( \'post_type\' => \'restaurants\', \'tax_query\' => array ( \'taxonomy\' => \'location\', \'field\' => \'slug\', \'terms\' => \'citya\' ), \'order_by\' => \'title\', \'order\' => \'ASC\' );
$query = new WP_Query ( $args );
while ( $query -> have_posts () ) {
$query -> the_post();
echo get_permalink($post->ID;
}
这给了我所有post\\u类型的“餐厅”帖子。是的,CityA的slug肯定是“CityA”,我仔细检查了所有的参数。