#42605 closed defect (bug) (fixed)
category_description() does not work properly since 4.9
Reported by: | Owned by: | boonebgorges | |
---|---|---|---|
Milestone: | 4.9.2 | Priority: | normal |
Severity: | normal | Version: | 4.9 |
Component: | Taxonomy | Keywords: | fixed-major |
Focuses: | Cc: |
Description
Hello,
since upgrading to 4.9 the category_description() function stopped working properly in my case. I use category_description() outside the loop and it returns an empty string.
I tracked down
get_term_field()
in wp-includes/taxonomy.php and
sanitize_term_field( $field, $term->$field, $term->term_id, $term->taxonomy, $context );
Does return only a string of the Category, but no description.
When I use 4.8.3 - I get the description.
Change History (20)
#2
@
7 years ago
Hi @torben.tschechne@…, does your second example work in 4.8.3? I think in this case you might have been using the function wrong. See - you're supplying the second parameter, but it's incorrect - if the $category
term is in fact from the product_cat
taxonomy, then why not just use product_cat
?
The Codex says that the second parameter is optional. So perhaps try with(product_cat
) and without the second parameter in 4.8.3 and if that works, then maybe it used to work incorrectly before.
#3
@
7 years ago
Hey @nikolov.tmw - I have not used term_description before. I have used
category_description( $category_id );
In 4.8.3 and it returned the description of the product category. But in 4.9 this stopped working - when using category_description I have not the possibility to define a taxonomy. So maybe this was a bug in 4.8.3 and I had a benefit from this bug ...?
When I use:
term_description($product_cat_id, 'product_cat');
It does work in 4.9
#4
@
7 years ago
- Resolution set to invalid
- Status changed from new to closed
category_description() function only return the default WordPress post category description. For custom taxonomy category description you have to use term_description() function.
https://codex.wordpress.org/Function_Reference/category_description
#11
follow-up:
↓ 12
@
7 years ago
@boonebgorges Should we throw a deprecation notice here in case people are expecting a different behavior?
#12
in reply to:
↑ 11
@
7 years ago
Replying to jorbin:
@boonebgorges Should we throw a deprecation notice here in case people are expecting a different behavior?
It's hard to see what this would look like. Uses of category_description()
and friends will work the same as how they worked prior to 4.9. If anything, I'd imagine that the appropriate change would be a _doing_it_wrong()
when passing a $term_id
to category_description()
that matches a term that is not, in fact, a category
. But this also seems as if it might be overkill for a fairly harmless bit of backward compat overhead.
#13
@
7 years ago
My thinking is that it will help people clean up and test code if they see a deprecated argument notice. I don't expect code to break now, but I do worry if there comes a time in the future where there is a desire to add a new parameter to term_description
and the committers then accidentally adding it as the 2nd parameter rather than the 3rd and code-breaking then.
Something along the lines of:
<?php function term_description( $term = 0, $deprecated = null ) { if ( null !== $deprecated ) { _deprecated_argument( __FUNCTION__ , '4.9.2', 'since terms are now split, taxonomy does not need to be passed to term_description' ) { }
#14
@
7 years ago
- Resolution fixed deleted
- Status changed from closed to reopened
@jorbin Ah yes, that makes perfect sense. Thanks for the clarification. I'll work on this.
#15
@
7 years ago
Thinking about this more, I think @jorbin is correct that we need to keep $deprecated
in the function signature, but I don't think it's something we need to expose to developers via _deprecated_argument()
.
#18
@
7 years ago
@boonebgorges Any particular reason to keep it hidden? My main argument for having _deprecated_argument
would be consistency and that's how core has traditionally deprecated arguments (to the best of my knowledge). My main argument against it would be my inability to think up a quality message to send with it.
#19
@
7 years ago
The semantics of "keep it hidden" make it sound like I'm pulling the wool over someone's eyes :) I just don't see the reason to fill up error logs with notices for something that is harmless. I grepped through the codebase before my commit above and found lots of instances of $deprecated
arguments that don't throw notices. That said, if the general agreement is that we should always throw notices in such cases, let's add it.
A quick update.
This happens when I want to determine the category description of a product category and this call:
in category_description. If I change this to
it works. However this is not happening in 4.8.3. So I assume that category_description() is not usable in 4.9 for product_cat anymore.