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

How to get a taxonomy by a term slug?

programmeradmin1浏览0评论

For example, if I have a custom taxonomy called "custom-category" and the term "WordPress", is there any way to get the taxonomy "custom-category" by term slug "wordpress".

This cant be used: get_term_by('slug', 'wordpress') since I have slug not term id.

USE CASE:

$tag = get_term_by('slug', 'wordpress');


$the_query = new WP_Query( array(
    'post_type' => 'custom-post',
    'tax_query' => array(
        array (
            'taxonomy' => $tag->taxonomy,
            'field' => 'slug',
            'terms'    => array( 'wordpress' )
        )
    ),
) );
发布评论

评论列表(0)

  1. 暂无评论