按术语显示自定义帖子类型

时间:2017-12-08 17:05:25

标签: filter custom-post-type term

需要根据类别显示自定义帖子类型。经过测试列出了这些术语并将其显示出来,因此正在阅读分类法,只是无法显示该帖子。

            $terms = get_terms('team');

        $args = array(
            'posts_per_page' => 30,
            'post_type' => 'team',
            'taxonomy'  => '$terms'
                );

                $q = new WP_Query( $args);

                    if ( $q->have_posts() ) {
                        while ( $q->have_posts() ) {
                        $q->the_post();

                        if( has_term( 'link-to-bio' )) {

                            // do stuff

2 个答案:

答案 0 :(得分:0)

知道了!通过https://developer.wordpress.org/reference/functions/get_the_terms/回复了代码:

$args = array(
            'posts_per_page' => 30,
            'post_type' => 'team'
                );

                $q = new WP_Query( $args);

                    if ( $q->have_posts() ) {
                        while ( $q->have_posts() ) {
                        $q->the_post();

                        $terms = get_the_terms( get_the_ID(), 'team' );

                        if ( $terms && ! is_wp_error( 'link-to-bio') ) {

                            // do stuff

答案 1 :(得分:0)

试试这个:

$args = array(
        'posts_per_page'  =>  30,
        'tax_query' => array(
        array(
                'taxonomy' => 'name of your taxonomy',
                'terms' => 'category id'
            ),
         ),
        'post_type'        => 'team',
        'post_status'      => 'publish'
        );