Get term by custom term meta and taxonomy

How to get term by custom term meta and taxonomy or how to filter tax_query by term meta instead slug/id?

function custom_pre_get_posts($query)
{
    global $wp_query;

    if ( !is_admin() && is_shop() && $query->is_main_query()  && is_post_type_archive( "product" )) 
    {
        $term = ???get_term_by_meta_and_taxonomy???('custom_meta_term','my_taxonomy');
        $t_id = $term['term_id'];
        $tax_query = array
        (
            array
            (
                'taxonomy' => 'my_taxoomy',
                'field' => 'id',
                'terms' => $t_id
            )
        );
        $query->set( 'tax_query', $tax_query );
    }
}
add_action( 'pre_get_posts', 'custom_pre_get_posts' );

3 s
3

Try This:

$args = array(
'hide_empty' => false, // also retrieve terms which are not used yet
'meta_query' => array(
    array(
       'key'       => 'feature-group',
       'value'     => 'kitchen',
       'compare'   => 'LIKE'
    )
),
'taxonomy'  => 'category',
);
$terms = get_terms( $args );

Leave a Comment