I am running get_term_children to check if a term has children. On a term which does not have have children wp returns an array containing a single int : 12 though that does not relate to any term. I did recently delete a child term though.
$hasChildren = get_term_children( $categories[$i]->term_id, 'my_tax' );
var_dump($hasChildren);
returns
array (size=1)
0 => int 12
WordPress saves all taxonomy children term ids in an option for caching purpose. The option is named
"$taxonomy_children"
. This option is created when you use the functionget_term_children
, but does not get updated that way. It’s only updated upon creating/updating parent or child term of that taxonomy using WP Admin UI.Rather than using WP Admin UI, if you deleted a term some other way, the option exists and therefore display wrong children information upon using
get_term_children
function. To solve this problem, you should manually delete the option named “$taxonomy_children” using thedelete_option
function or directly from your phpMyAdmin