最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

custom taxonomy - Display just the Post's parent Category, not child

programmeradmin3浏览0评论

I want to display all post under a parent category (custom taxonomy) ONLY!.

Here's what I've done so far:'

<?php
$args_1 = array(
    'fields' => 'ids',
);

$custom_taxterms = wp_get_object_terms(
    $post->ID,
    'product_type',
    $args_1
);

$args_2 = array(
    'post_type'      => 'product',
    'post_status'    => 'publish',
    'posts_per_page' => -1,
    'orderby'        => 'date',
    'order'          => 'ASC',
    'tax_query'      => array(
        array(
            'taxonomy'         => 'product_type',
            'field'            => 'id',
            'terms'            => $custom_taxterms,
            'include_children' => false,
        ),
    ),
    'post__not_in'   => array( $post->ID ),
);

$related_items = new WP_Query( $args_2 );

This displays all the posts including the sub categories, which I don't want to.

Thanks!!

发布评论

评论列表(0)

  1. 暂无评论