How to get a taxonomy by a term slug?

Question

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
Md Shihab Uddin 4 years 2020-03-10T20:53:02-05:00 0 Answers 86 views 0

Leave an answer

Browse
Browse