[wp-hackers] Weird behavior (maybe a "bug") in get_term_link()

Davit Barbakadze jayarjo at gmail.com
Wed May 19 12:49:54 UTC 2010


I have registered custom taxonomy and what I do is - I retrieve list
of terms with get_terms(), then loop through them and generate linked
list with get_term_link(). Pretty simple task I guess. But it took me
an hour or even more to get it so. The problem was that
get_term_link() returned a link to a taxonomy page and not a taxonomy
term page, so that all links for all the various terms were identical
and wrong.

I checked everything step by step. term_id was numeric, taxonomy was
registered, I was able to retrieve term by mere get_term(), but I was
still getting blank urls. To keep my troubles short, I'll just say
that it brought me to this block of code in get_term_link()

if ( is_int($term) ) {
	$term = &get_term($term, $taxonomy);
} else {
	$term = &get_term_by('slug', $term, $taxonomy);
}

Turned out that it was triggering second call - get_term_by() and not
the first as one may logically assume. While $term was indeed numeric,
for some reason it was not being passed as int and is_int() which
strictly checks for integers and not general numerical values, failed
to serve the request in proper manner.

Passing my term_id as (int)$term_id has solved the problem. But I
think it's not what the one may expect in this case. Is there any
reason why is_int() cannot be replaced by is_numerical() ?

-- 
Davit Barbakadze


More information about the wp-hackers mailing list