get_terms (or tax_query) for term of current post?

I’ve seen many solutions but none seems to work for me… I’ve got a grid off the loop/content on single.php that renders the whole grid as is, so I use the function as below which works fine, but only if I specify the exact taxonomy term (client-1).

function my_query_args($query_args, $grid_name) {
if ($grid_name == 'client-grid) {
    $query_args['tax_query'] = array(
        array(
            'taxonomy' => 'category',
            'field'    => 'slug',
            'terms'    => 'client-1'
        ),
    );
}
return $query_args;
}
add_filter('tg_wp_query_args', 'my_query_args');

But I want the term of the current post instead so I thought that below would work, but it renders all posts in the grid no matter what I do.

function my_query_args($terms_list, $grid_name) {
if ($grid_name == 'client-grid') {

    $terms_list = get_terms
        (array(
            'taxonomy'=>'category',
            'parent'=>0
        )
    );  
}
return $terms_list;

}
add_filter('tg_wp_query_args', 'my_query_args'); 

Thankful for any input.

Read more here: get_terms (or tax_query) for term of current post?

Leave a Reply

Your email address will not be published. Required fields are marked *