Get tags name under custom taxonomy in wordpress

I want to getshow only available tags under custom taxonomy. Here's my code;$tax = $wp_query->get_queried_objec

I want to get/show only available tags under custom taxonomy. Here's my code;

$tax = $wp_query->get_queried_object(); // print current taxonomy 

$args = array( 
    'post_type' => 'types', // CPT
    'taxonomy' => $tax->slug, //get current taxonomy page
    'orderby' => 'name',
    'order' => 'DESC',
    'hide_empty' => false
); 

$tags = get_tags( $args );
    foreach ( $tags as $tag ) {
    echo '<li>'.$tag->name.'</li>';
}

My problem is in other page which don't have the tags under the taxonomy always shows. Any suggestion to this?

I want to get/show only available tags under custom taxonomy. Here's my code;

$tax = $wp_query->get_queried_object(); // print current taxonomy 

$args = array( 
    'post_type' => 'types', // CPT
    'taxonomy' => $tax->slug, //get current taxonomy page
    'orderby' => 'name',
    'order' => 'DESC',
    'hide_empty' => false
); 

$tags = get_tags( $args );
    foreach ( $tags as $tag ) {
    echo '<li>'.$tag->name.'</li>';
}

My problem is in other page which don't have the tags under the taxonomy always shows. Any suggestion to this?

Share Improve this question edited Oct 15, 2019 at 1:09 mrrsb asked Oct 10, 2019 at 7:52 mrrsbmrrsb 1012 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 0

You can use the following code to get all tags in a taxonomy.

<?php

$tags = get_terms(
    array(
        'taxonomy' => 'your_taxonomy',
    )
);

foreach( $tags as $tag ) {
    echo $tag->name;
}

You can get the tags of current post using:

$tax = $wp_query->get_queried_object(); // print current taxonomy 

$args = array( 
    'orderby' => 'name',
    'order' => 'DESC',
);

if( 'types' == get_post_type( get_the_ID() ) ) {
    $tags = wp_get_object_terms( get_the_ID(),  $tax->slug, );
    if ( ! empty( $tags ) ) {
        if ( ! is_wp_error( $tags ) ) {
            foreach( $tags as $tag ) {
                echo '<li>'.esc_html( $tag->name ).'</li>';
            }
        }
    }
}

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745080431a4610091.html

相关推荐

  • Get tags name under custom taxonomy in wordpress

    I want to getshow only available tags under custom taxonomy. Here's my code;$tax = $wp_query->get_queried_objec

    12小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信