[wp-trac] [WordPress Trac] #25429: `get_the_category_by_ID` triggers PHP notice on non-existent category
WordPress Trac
noreply at wordpress.org
Tue Feb 11 14:36:34 UTC 2014
#25429: `get_the_category_by_ID` triggers PHP notice on non-existent category
-----------------------------------+------------------------------
Reporter: ericmann | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Taxonomy | Version: 2.3
Severity: normal | Resolution:
Keywords: has-patch 2nd-opinion | Focuses:
-----------------------------------+------------------------------
Comment (by bobbingwide):
As a workaround for this problem I have coded something like
{{{
$category = get_term( $ID, 'category' );
if ( is_wp_error( $category ) || is_null( $category) ) {
$catname = "Invalid category - please Delete ";
} else {
$catname = $category->name;
}
}}}
which is almost exactly the same as I would have had to have written to
handle the results from a 'fixed' version of get_the_category_by_ID().
Given that you can get a fatal from echo get_the_category_by_ID( 0 ); then
I would support either the deprecation of the function or some further
work to make the function more useful as a template tag.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/25429#comment:7>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list