Closed bruno-barros closed 9 years ago
There is no 'term'
query variable, because you are setting taxonomy query via 'tax_query'
argument.
When you don't use Cortex, WordPress set 'term'
variable from the url, so you can get it.
You can do in 2 ways:
$tax_query = reset(get_query_var('tax_query'));
$term = $tax_query[0];
So you get 'tax_query'
argument and then the 'terms'
argument. This will work for Cortex, but not when you get the page using standard WordPress urls.
If you need a way that works in both cases you can:
global $wp_query;
$term = $wp_query->tax_query->queries[0]['terms'][0];
I understand is not exactly user friendly, bu you can write an helper function to also perform some checks and avoid notices in case the term is not defined:
function first_queried_term() {
global $wp_query;
if (isset($wp_query->tax_query) && ! empty($wp_query->tax_query)) {
return reset(reset($wp_query->tax_query->queries)['terms']);
}
return false;
}
All right! Thak you. For a moment a thought Cortex was changing the way WP works.
I made this route to order posts by meta
date-init
.Without this route I can get the taxonomy term by
get_query_var('term')
, but with this route I can't. Am I missing something? Changing the order of the global query shouldn't alter the global vars used by WordPress.