#35265 closed defect (bug) (duplicate)
get_the_terms return on non-existing term
| Reported by: | tivnet | Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | |
| Component: | Taxonomy | Version: | 4.4 |
| Severity: | normal | Keywords: | |
| Cc: | Focuses: |
Description
<?php function get_the_terms( $post, $taxonomy ) { if ( ! $post = get_post( $post ) ) return false; $terms = get_object_term_cache( $post->ID, $taxonomy ); if ( false === $terms ) { $terms = wp_get_object_terms( $post->ID, $taxonomy ); // ---------- PROPOSED (should we return WP_Error or false here?) if ( is_wp_error( $terms ) ) { return $terms; } // ---------- $to_cache = array();
Attachments (1)
Change History (10)
#2
follow-up:
↓ 4
@
11 years ago
- Component Taxonomy → General
* @return array|false|WP_Error Array of term objects on success, false if there are no terms * or the post does not exist, WP_Error on failure.
This description suggests that false should be returned.
However, if I am not mistaken, I was getting WP_Error in this case before 4.4
#3
in reply to: ↑ 1
@
11 years ago
- Resolution → duplicate
- Status new → closed
Replying to swissspidy:
Related: #34723
Yep, that's the same case. Not sure, still, if need to return WP_Error as it was before (according to my tests).
Thank you!
#4
in reply to: ↑ 2
;
follow-up:
↓ 5
@
11 years ago
- Milestone Awaiting Review
Replying to tivnet:
* @return array|false|WP_Error Array of term objects on success, false if there are no terms * or the post does not exist, WP_Error on failure.This description suggests that
falseshould be returned.
However, if I am not mistaken, I was getting
WP_Errorin this case before 4.4
It clearly suggests that it returns either false or a WP_Error object, so I don't see a problem here.
There are is_wp_error checks later on and the get_the_terms filter clearly says that $terms can be a WP_Error object.
Long story short: Your patch prevents the get_the_terms filter being called, otherwise nothing else changes.
#5
in reply to: ↑ 4
@
11 years ago
Replying to swissspidy:
Long story short: Your patch prevents the
get_the_termsfilter being called, otherwise nothing else changes.
The main idea was to avoid notice on non-array.
#6
@
11 years ago
Specifically:
Notice: Trying to get property of non-object in wp-includes\category-template.php on line 1153
($term->data)
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
Patch returning WP_Error