-2

So I want to be able to get all terms from a custom taxonomy. My custom taxonomy has been created in specific languages; doing a simple WP_Term_Query isn't enough as that only gets the terms for my default language.

I've tried multiple ways of getting the terms I want such as:

  • Passing in surpress_filters to the WP_Term_Query class
  • Using get_terms instead as that behaves differently (explained below)
  • Removing "get_terms_filter" sitepress filter manually

All of these solutions give me only the en-gb (default language) records.

Behind trying get_terms: Method get_term uses a new WP_Term_Query without parameters Following that it can call ->query($args) rather than the conventional ->terms This query doesn't apply filters to the data.

Custom Taxonomies that I am Querying for...

Justin
  • 150
  • 2
  • 7

1 Answers1

1

After some further searching of the plugin's core code I found three filters with priorites that need to be manually removed in order to get the desired result.

This should work to get you all of the terms in a translated custom taxonomy:

    // Disable WPML supress_filter override
    global $sitepress;
    remove_filter(
        "get_terms_args", 
        [$sitepress, "get_terms_args_filter"], 
        10
    );
    remove_filter(
        "get_term", 
        [$sitepress, "get_term_adjust_id"], 
        1
    );
    remove_filter(
        "terms_clauses", 
        [$sitepress, "terms_clauses"], 
        10
    );

It's advised that you re-add those filters after you get your data:

// Enable WPML Taxonomy supress_filter override
    add_filter(
        "get_terms_args", 
        [$sitepress, "get_terms_args_filter"], 
        10,
        2
    );
    add_filter(
        "get_term", 
        [$sitepress, "get_term_adjust_id"], 
        1
    );
    add_filter(
        "terms_clauses", 
        [$sitepress, "terms_clauses"], 
        10,
        4
    );
Justin
  • 150
  • 2
  • 7