I have a custom post tipe ("artigo"), and this CPT has a registered taxonomy ("artigo_eixo"), with 3 registered terms in it.
I want to show, in that page, a sidebar listing all terms, except the current term, in the page that lists all posts with that term (http://localhost/mytaxonomy/current_term/)
However, I can't exclude the current term from the query.
I'm trying to get a list of taxonomy terms, but exclude a certain term from this list. I'm trying to follow the codex examples, but I'm having no success, using either get_terms()
or WP_Term_query()
.
There are 3 terms and the IDs are 13,14,15. There are no posts or CPT items with those IDs.
I just tested get_queried_object_id()
and it seems to be returning the proper term IDs of the term being shown -- that is, if I am viewing the URL of the term with ID 13, the function returns 13, and so on.
It also doesn't work using hardcoded values, be it a string, an integer, or an array of any of those types. Neither won't work:
'exclude' => 14
'exclude' => '14'
'exclude' => array(14)
'exclude' => array('14')
There are no errors displayed by PHP or the WP debug log.
get_terms
if (is_tax( 'artigo_eixo' )) {
$current_eixo = get_queried_object_id();
$args = array(
'taxonomy' => 'artigo_eixo',
'exclude' => $current_eixo
);
$eixos = get_terms( $args );
WP_Term_query
if (is_tax( 'artigo_eixo' )) {
$current_eixo = get_queried_object_id();
$args = array(
'taxonomy' => array('artigo_eixo'),
'exclude' => $current_eixo
);
$eixos = new WP_Term_Query( $args );
$eixos = $eixos->terms;