Get term of post belong

I had this query:

$args=array(
    'post_type' => array('product'), 
    'order' => 'DESC', 
    'orderby' => 'rand',
    'showposts' => 24
);

query_posts( $args );
if(have_posts()) : while(have_posts()) : the_post();
?>
    <div class="col-xs-12 col-s-6 col-sm-4 col-md-3 our-products">
        <a class="products-img" href="<?php the_permalink();?>"><?php if ( has_post_thumbnail() ) {the_post_thumbnail('product-size',array('class' => 'img-responsive'));}?></a>
        <a class="products-tit" href="<?php the_permalink();?>">
          <h2><b><?php the_title();?></b></h2>
        </a>
    </div>
<?php 
endwhile; endif;
wp_reset_query();
?>

I need to get tax term of product belong to it.

Read More

Example:

I had Category: Products -> Men fashion/Women fashion -> T-shirt -> product A.
How can i get the term of T-shirt which product A belong to it?

Related posts

1 comment

  1. You can use WordPress get_the_terms() function for this purpose.

    Here is the example:

    $_terms = get_the_terms( $post->ID , 'Your Taxonomy' );
    

    In “Your Taxonomy” you put the name of the taxonomy that you just registered e.g. product-category

    So just like this:

    $_terms = get_the_terms( $post->ID , 'product-category' );
    

    And then

    <?php
         foreach($_terms as $_term) {
    ?>
            <a href="<?php echo get_term_link($_term->slug, 'product-category') ?>">
               <?php echo $_term->name ?>
            </a>
    <?php
         }
    ?>
    

    This function get_term_link() is use for term link.

    Hope this will help you.

Comments are closed.