I’m using the pre_get_posts
hook to order the main query on all my custom post type / taxonomy pages using a custom meta value. As part of the logic, I am trying to determine which taxonomy is currently being displayed by using get_query_var('taxonomy')
, however no matter what I try, it keeps returning a blank string:
function sort_query($query)
...
if (is_tax()){
...
echo get_query_var('taxonomy'); // Empty
echo get_query_var($query->query_vars['taxonomy']); // Empty
...
}
}
add_action('pre_get_posts', 'sort_query');
Any help would be greatly appreciated; thanks!
Did you try this?
Happy Coding,
Kuchenundkakao