term_exists returns NULL

According to the codex ( http://codex.wordpress.org/Function_Reference/term_exists ), term_exists returns some mixed results but not NULL. In my case, I’m getting NULL, what am I doing wrong?

In this particular example ‘Videos’ term does not exist under category. Shouldn’t it be returning a false or 0? Why NULL?

$term_exists_results = term_exists($term, 'category');

echo "<p>term_exists('{$term}', 'category')?"; 
echo "<blockquote>";
var_dump ($term_exists_results);
echo "</blockquote>";


Taxonomy: [category Term: [Videos]

term_exists('Videos', 'category')?



It can return null in some cases if you look at the code: http://core.trac.wordpress.org/browser/tags/3.3.2/wp-includes/taxonomy.php#L1492

The method get_var returns null if no result is found. If you check with “==” and not “===” that should work with false or 0.

Source : Link , Question Author : Average Joe , Answer Author : Mathias

Leave a Comment