• Resolved Rudá Almeida

    (@rudaalmeida)


    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 (https://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.

    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;
Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter Rudá Almeida

    (@rudaalmeida)

    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')
    • This reply was modified 7 years, 11 months ago by Rudá Almeida.
    Thread Starter Rudá Almeida

    (@rudaalmeida)

    Turns out there was a function hooking the filter list_terms_exclusions, and the return was inside a logically faulty conditional. I fixed it and now the term query exclusion works as intended.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Excluding a term ID from a term query?’ is closed to new replies.