Opened 9 months ago
Last modified 6 months ago
#21606 new defect (bug)
term_exists returns 0 and null
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Priority: | normal | Milestone: | Future Release |
| Component: | Taxonomy | Version: | 3.4.1 |
| Severity: | normal | Keywords: | has-patch |
| Cc: |
Description
The function term_exists in wp-includes/taxonomy.php has two different return values, 0 and null. The function does a few checks and returns 0 if the condition of the check is not met. If the checks are met, the return value will be the result of a $wpdb->get_row or $wpdb->get_var. If the term is not found in the database the methods get_row and get_var will return null.
Because of the different type of return values it's not possible to do a strict check on the return value to see if a term was found. I've changed the return 0 in term_exists to return null, so that if there is no term found the result of term_exists will always be null.
Attachments (2)
Change History (8)
barrykooij — 9 months ago
comment:3
in reply to:
↑ 2
barrykooij — 9 months ago
Replying to ocean90:
Should probably do the same with post_exists.
Indeed, should I create a separate ticket for this?
You can upload another patch on this ticket, since it seems similar enough.
comment:5
SergeyBiryukov — 9 months ago
Because of the different type of return values it's not possible to do a strict check on the return value to see if a term was found.
Consistency is good, but I wonder where the need for a strict check comes from.
It should be possible to check with if ( ! term_exists( 'events', 'post_tag' ) ) if a term was not found, unless I'm missing something.

Taxonomy Patch