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

plugins - Can't get custom posts of taxonomy to show

programmeradmin0浏览0评论

I have a custom post type called 'brand', with a taxonomy of 'brand-categories'. try as I might, I cannot find a way to display a list of posts in the current taxonomy. can anyone help?

<?php
function List_Brands_of_Category(){
$terms = wp_get_post_terms( $post->ID, 'brand-categories'); 

foreach ( $terms as $term ) {
    echo "$term->ID"; 
}
$args = array(
    'post_type' => 'brand',
    'tax_query' => array(
        'relation' => 'AND',
        array(
            'taxonomy' => 'brand-categories',
            'field'    => 'ID',
            'terms'    => array($term->term_id)
        )
    ),
);// end args



$query = new WP_Query($args); ?>
    <?php       
    if ( $query->have_posts() ) {
        while ( $query->have_posts() ) {
            echo 'Brand';
            $query->the_post(); 
        } 
    } 
    else {?>

    <p><?php _e( 'Sorry, no posts matched your criteria.' ); 
    }

    ?></p>

<?php 
}

  function DMBrandofCategory_Cleanse() {
     ob_start();
        List_Brands_of_Category();
      return ob_get_clean();
 }
 add_shortcode('WC_BOC', 'DMBrandofCategory_Cleanse');
 ?>

I have a custom post type called 'brand', with a taxonomy of 'brand-categories'. try as I might, I cannot find a way to display a list of posts in the current taxonomy. can anyone help?

<?php
function List_Brands_of_Category(){
$terms = wp_get_post_terms( $post->ID, 'brand-categories'); 

foreach ( $terms as $term ) {
    echo "$term->ID"; 
}
$args = array(
    'post_type' => 'brand',
    'tax_query' => array(
        'relation' => 'AND',
        array(
            'taxonomy' => 'brand-categories',
            'field'    => 'ID',
            'terms'    => array($term->term_id)
        )
    ),
);// end args



$query = new WP_Query($args); ?>
    <?php       
    if ( $query->have_posts() ) {
        while ( $query->have_posts() ) {
            echo 'Brand';
            $query->the_post(); 
        } 
    } 
    else {?>

    <p><?php _e( 'Sorry, no posts matched your criteria.' ); 
    }

    ?></p>

<?php 
}

  function DMBrandofCategory_Cleanse() {
     ob_start();
        List_Brands_of_Category();
      return ob_get_clean();
 }
 add_shortcode('WC_BOC', 'DMBrandofCategory_Cleanse');
 ?>
Share Improve this question edited Sep 13, 2019 at 9:28 Chetan Vaghela 2,4084 gold badges10 silver badges16 bronze badges asked Sep 13, 2019 at 9:23 Captain DandoCaptain Dando 1339 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0
$args = array(
    'post_type' => 'brand',
    'tax_query' => array(
        'relation' => 'AND',
        array(
            'taxonomy' => 'brand-categories',
            'field'    => 'name',
            'terms'    => get_queried_object()
        )
    ),
);// end args
发布评论

评论列表(0)

  1. 暂无评论