Make WordPress Core

Opened 16 years ago

Closed 14 years ago

#5381 closed defect (bug) (duplicate)

type mismatch between is_term and get_term_by

Reported by: tellyworth's profile tellyworth Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: General Keywords:
Focuses: Cc:


get_term_by() and similar functions return a row that includes the term_id as a numeric string. is_term() requires that a term_id be passed in as an int; a numeric string will fail.

I don't know what the solution is but this seems like a likely cause of bugs. Code that looks like it ought to work fails:

	$term_id = get_term_by('name', $term, $taxonomy);
	if ( is_term($term_id) ) ... // fails because is_term returns false

test_is_term_type() in reproduces the problem.

There are other related type inconsistencies in taxonomy.php also - for example, is_term() returns a 0, NULL, term ID, WP_Error object or row object depending on the context and circumstances, which makes handling the return result difficult. Mostly due I think to the functions being overloaded to magically handle both term ids and names.

Change History (2)

#1 @ryan
16 years ago

Overloading was a mistake, but here we are. Part of the problem is that we changed sanitize_term() to return immediately for the raw context. It should probably do int casts for the IDs before returning.

#2 @Denis-de-Bernardy
14 years ago

  • Milestone 2.9 deleted
  • Resolution set to duplicate
  • Status changed from new to closed

there are 2 or 3 dups of this one. closing.

Note: See TracTickets for help on using tickets.