terms – How to fix / debug get_terms suddenly showing no results?

Until what I just discovered, my taxonomy-company.php theme file successfully generated a recessed list of each "business"family tree of the term taxonomy.

C & # 39; is, business is a hierarchical taxonomy. On the terms archive page, we get the first parent of the company and, if so, all his children, by displaying the full list in a sidebar.

But he became mean for some unknown reason.

I will omit the last tree code display function below because, for the moment, I speculate that the problem is more serious.

        / ************************************************ * *********** /
/ * * /
/ * Get the family tree of the company * /
/ * * /
/ ************************************************ * *********** /

// $ organization = & # 39; groupm & # 39;
$ taxonomy_name = & # 39; company & # 39 ;;

/ **
* Get the term first level, cf. https://wordpress.stackexchange.com/a/119268/39300
* /
get_top_level_term function ($ term, $ taxonomy) {
if ($ term-> parent == 0) returns $ term;
$ parent = get_term ($ term-> parent, $ taxonomy);
return get_top_level_term ($ parent, $ taxonomy);
}
$ topmost = get_top_level_term ($ organization, $ taxonomy_name);

$ term_id = $ topmost-> term_id;
/ * Works well here * /


/ **
* Get the family
* /
$ args = array (
& # 39; parents & # 39; => $ topmost-> term_id,
)
$ family = get_terms ($ taxonomy_name, $ args);
// print_r ($ family); / * It went wrong * /
$ family_size = count ($ family);

In the example of access to the term page for the company "GroupM" (slug GroupM), function get_top_level_term () here successfully retrieves the term from its parent "WPP" (slug wpp) and we put the identifier of the latter (7436) in $ term_id.

Until here everything is fine. However, when I feed that $ term_id at get_terms () as relative parameter, trying to get all the terms under WPP, the $ family is now an empty board (Board ()). And $ family_sizeis therefore 0. This is incorrect – WPP contains many company terms.

It did not happen before. And that now means that the following code to display the enterprise tree will not work. Previously, it worked fully with this code. This unexpected failure is really problematic.

I've certainly made changes to my site, but not in the partial template file of the sidebar that does it. In fact, I have just restored from a backup: the sidebar file, the taxonomy-company.php file, another partial file that it calls and a file containing specific functions to it. taxonomy. But there is no change.

I wonder if I've introduced a filter on get_terms anywhere, or if it's even a thing.

I've done a full follow-up of calls and I find that this segment is repeating itself, but it does not bring me any light …

/home/mysite/public_html/wp-content/themes/bs4boiler-platform/partials/page-blocks/org/org_sidebar.php(123): function created at runtime: 1: string & # 39; get_term & # 39; (length = 8)
/home/mysite/public_html/wp-content/themes/bs4boiler-platform/partials/page-blocks/org/org_sidebar.php(123): function created at runtime: 1: string & # 39; get_company & # 39; (length = 11)
/home/mysite/public_html/wp-content/themes/bs4boiler-platform/partials/page-blocks/org/org_sidebar.php(123): function created at runtime: 1: string & # 39; wp_parse_str & # 39; (length = 12)
/home/mysite/public_html/wp-content/themes/bs4boiler-platform/partials/page-blocks/org/org_sidebar.php(123): function created at runtime: 1: string & # 39; get_terms_defaults & # 39; (length = 18)
/home/mysite/public_html/wp-content/themes/bs4boiler-platform/partials/page-blocks/org/org_sidebar.php(123): function created at runtime: 1: string parse_term_query & # 39; (length = 16)
/home/mysite/public_html/wp-content/themes/bs4boiler-platform/partials/page-blocks/org/org_sidebar.php(123): function created at runtime: 1: string & # 39; pre_get_terms & # 39; (length = 13)
/home/mysite/public_html/wp-content/themes/bs4boiler-platform/partials/page-blocks/org/org_sidebar.php(123): function created at runtime: 1: string & get_terms_args & # 39; (length = 14)
/home/mysite/public_html/wp-content/themes/bs4boiler-platform/partials/page-blocks/org/org_sidebar.php(123): function created at runtime: 1: string & # 39; pre_option_company_children & # 39; (length = 27)
/home/mysite/public_html/wp-content/themes/bs4boiler-platform/partials/page-blocks/org/org_sidebar.php(123): function created at runtime: 1: string & # 39; alloptions & # 39; (length = 10)
/home/mysite/public_html/wp-content/themes/bs4boiler-platform/partials/page-blocks/org/org_sidebar.php(123): function created at runtime: 1: string & # 39; option_company_children & # 39; (length = 23)
/home/mysite/public_html/wp-content/themes/bs4boiler-platform/partials/page-blocks/org/org_sidebar.php(123): function created at runtime: 1: string & get_terms_orderby & # 39; (length = 17)
/home/mysite/public_html/wp-content/themes/bs4boiler-platform/partials/page-blocks/org/org_sidebar.php(123): function created at runtime: 1: string & # 39; list_terms_exclusions & # 39; (length = 21)
/home/mysite/public_html/wp-content/themes/bs4boiler-platform/partials/page-blocks/org/org_sidebar.php(123): function created at runtime: 1: string & # 39; sanitize_key & # 39; (length = 12)
/home/mysite/public_html/wp-content/themes/bs4boiler-platform/partials/page-blocks/org/org_sidebar.php(123): function created at runtime: 1: string & # 39; get_meta_sql & # 39; (length = 12)
/home/mysite/public_html/wp-content/themes/bs4boiler-platform/partials/page-blocks/org/org_sidebar.php(123): function created at runtime: 1: string & get_terms_fields & # 39; (length = 16)
/home/mysite/public_html/wp-content/themes/bs4boiler-platform/partials/page-blocks/org/org_sidebar.php(123): function created at runtime: 1: string & # 39; terms_clauses & # 39; (length = 13)
/home/mysite/public_html/wp-content/themes/bs4boiler-platform/partials/page-blocks/org/org_sidebar.php(123): function created at runtime: 1: string & # 39; query & # 39; (length = 5)
/home/mysite/public_html/wp-content/themes/bs4boiler-platform/partials/page-blocks/org/org_sidebar.php(123): function created at runtime: 1: string & pre_option_db_version & # 39; (length = 21)
/home/mysite/public_html/wp-content/themes/bs4boiler-platform/partials/page-blocks/org/org_sidebar.php(123): function created at runtime: 1: string & # 39; alloptions & # 39; (length = 10)
/home/mysite/public_html/wp-content/themes/bs4boiler-platform/partials/page-blocks/org/org_sidebar.php(123): function created at runtime: 1: string option_db_version & # 39; (length = 17)
/home/mysite/public_html/wp-content/themes/bs4boiler-platform/partials/page-blocks/org/org_sidebar.php(123): function created at runtime: 1: string & # 39; sanitize_key & # 39; (length = 12)
/home/mysite/public_html/wp-content/themes/bs4boiler-platform/partials/page-blocks/org/org_sidebar.php(123): function created at runtime: 1: string & # 39; query & # 39; (length = 5)
/home/mysite/public_html/wp-content/themes/bs4boiler-platform/partials/page-blocks/org/org_sidebar.php(123): function created at runtime: 1: string & # 39; pre_option_company_children & # 39; (length = 27)
/home/mysite/public_html/wp-content/themes/bs4boiler-platform/partials/page-blocks/org/org_sidebar.php(123): function created at runtime: 1: string & # 39; alloptions & # 39; (length = 10)
/home/mysite/public_html/wp-content/themes/bs4boiler-platform/partials/page-blocks/org/org_sidebar.php(123): function created at runtime: 1: string & # 39; option_company_children & # 39; (length = 23)
/home/mysite/public_html/wp-content/themes/bs4boiler-platform/partials/page-blocks/org/org_sidebar.php(123): function created at runtime: 1: string & # 39; query & # 39; (length = 5)

There is no error, warning or notice to the affected party. So, I do not know how to find what broke that.

How can I fix it?

I note that:

a) My site now seems to be 4.9.8 (I do not remember doing it).

b) According to the Codex for get_terms ():

Since version 4.5.0, taxonomies should be passed via the 'taxonomy' argument
in the $ args array:

$ terms = get_terms (array (
& # 39; taxonomy & # 39; => & # 39; post_tag & # 39;
& # 39; hide_empty & # 39; => false,
));

I have therefore tried to update my $ args specification with the new wording. But that does not make the difference. A difference, with the old or the new method, becomes obvious by adding & # 39; hide_empty & # 39; => false to be – who reveals all the terms of the company to have 0 account!

enter the description of the image here

This is confirmed by doing:

        $ myterm = get_term (7436, & # 39;)
echo & # 39; account: & # 39; $ myterm-> count;

But these new accounts are not true. There are many posts with the terms company "groupm", "wpp" and others in the family.

This may be a reason why the thing has stopped working.

Maybe the attention should be turned to – how can I fix the post zero accounts business taxonomy terms? (Or is it still possible that something I did elsewhere in another file is the cause?)

Sadly, wp_update_term_count_now (7436, & # 39; company); does not accurately update the "wpp" (7436) count beyond 0.