显示自定义邮件类型中的特定分类术语

时间:2017-10-26 作者:Michael G

我看过多篇帖子,但运气不好。我需要在现有目的中使用循环,但我永远也弄不清楚如何在自定义post类型中返回自定义分类法的术语。这是我的代码:

<?php $loop = new WP_Query( 

    \'post_type\' => \'dealmaker_pt\', 
    \'taxonomy\' => \'topics\',
    \'field\' => \'slug\',
    \'terms\' => \'dealoftheweek\',
    \'posts_per_page\' => 50,
    \'offset\' => 1 ) 
); 
        while ( $loop->have_posts() ) : $loop->the_post(); 
?>

stuffs here

<?php endwhile; wp_reset_query(); ?>
我的帖子类型是dealmaker_pt 我的分类法是topics 我试图显示dealoftheweek.

我该怎么做呢?

1 个回复
最合适的回答,由SO网友:Ravi Patel 整理而成

请对此使用有效格式Taxonomy Parameters

示例:

$args = array(
    \'tax_query\' => array(
        array(
            \'taxonomy\' => \'topics\',
            \'field\'    => \'slug\',
            \'terms\'    => \'dealoftheweek\',
        ),
    ),
    \'post_type\' => \'dealmaker_pt\',
    \'posts_per_page\' => 50,
    \'offset\' => 1 
);
$query = new WP_Query( $args );

结束

相关推荐

Search Media by taxonomy

如何根据前端的分类法搜索媒体?以下查询显示我希望通过搜索返回的内容:$args = array( \'post_type\' => \'attachment\', \'post_status\' => \'inherit\', // for PDFs \'post_mime_type\' => \'application/pdf\', // if you need PDFs from a specific media c