1

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');
 ?>
0
$args = array(
    'post_type' => 'brand',
    'tax_query' => array(
        'relation' => 'AND',
        array(
            'taxonomy' => 'brand-categories',
            'field'    => 'name',
            'terms'    => get_queried_object()
        )
    ),
);// end args
  • Hey {user} nice code. Your answer is off to a good start. Please consider explaining how and why this code solves the problem so others can learn from it. Check the guide to answers for further advice. – Matthew Brown aka Lord Matt Sep 13 at 10:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.