Opened 8 years ago
Last modified 2 years ago
#40696 accepted enhancement
no chance to control wp_count_terms ()
Reported by: | krizkroz | Owned by: | audrasjb |
---|---|---|---|
Milestone: | Future Release | Priority: | normal |
Severity: | normal | Version: | 4.7.4 |
Component: | Taxonomy | Keywords: | good-first-bug has-patch |
Focuses: | Cc: |
Description
Hey!
I'm wondering if i have no chance to filter the resulting number of wp_count_terms ().
Theres no filter available there.
wp_count_terms () calls get_terms () but it returns the result of $term_query before ("Count queries are not filtered, for legacy reasons.") the "get_terms" filter is appliable. So i see no chance to control result of wp_count_terms () without (heavy) diggin in to WP_Term_Query().
Is there a chance for a filter before the function returns in this case?
thank you a lot,
Christian
Attachments (4)
Change History (21)
#2
@
5 years ago
- Keywords needs-patch added
- Milestone changed from Awaiting Review to Future Release
- Type changed from feature request to enhancement
#4
@
5 years ago
- Keywords needs-patch removed
- Resolution set to invalid
- Status changed from new to closed
By mistake changed to invalid.
#6
@
5 years ago
- Keywords has-patch added
Added a filter to modify the arguments of wp_count_terms. Similar to above solution but I think having a filter name like wp_count_terms_args would make more sense.
Checkout the diff, I just uploaded below.
#7
@
5 years ago
@amitkumarsingh @jignashu Wont it be better to have a filter directly for the result?
#8
@
5 years ago
@jaydeeptrivedi404 yes, it is good to have it on the result as well but it also required before calling the get_terms() to modify the arguments of the function.
#9
@
5 years ago
Hello.
I don't understand some of your proposals regarding of initial request.
As I explain in ticket #49411 (duplicate), the need is to filter result exactly the same way wp_count_posts
(wp-includes/posts.php) does.
wp_count_terms
function should then terminate with:
return apply_filters('wp_count_terms', get_terms($args), $taxonomy, $args);
Thank you.
#10
@
5 years ago
Filtering the result give user more control and make wp_count_terms mostly coherent with wp_count_posts function.
In another hand, I think that filtering args should be done by get_terms instead of wp_count_terms.
#11
@
4 years ago
Hello.
4 years later, the need for a filter call before returning is still present.
Would it be possible to take this request into account ?
Filtering the args could by interesting but doesn't give the hability to return terms that are not present in the database (and this is exactly the need).
Regards.
#14
@
2 years ago
- Milestone changed from Future Release to 6.1
- Owner set to audrasjb
- Status changed from reopened to accepted
Hello,
Sorry for the long delay and thank you for the patch @ddu66.
Moving for 6.1 consideration and self-assigning for review.
This ticket was mentioned in PR #2875 on WordPress/wordpress-develop by audrasjb.
2 years ago
#15
- Keywords needs-refresh removed
Trac ticket: https://core.trac.wordpress.org/ticket/40696
#16
follow-up:
↓ 17
@
2 years ago
I'd like to wrap up #40351 before putting this in.
The intention is to improve the performance of term counts significantly so there is a risk adding a filter would block that in an effort to maintain backward compatibiltiy.
#17
in reply to:
↑ 16
@
2 years ago
- Milestone changed from 6.1 to Future Release
Replying to peterwilsoncc:
I'd like to wrap up #40351 before putting this in.
The intention is to improve the performance of term counts significantly so there is a risk adding a filter would block that in an effort to maintain backward compatibiltiy.
I agree with this. Since #40351 is still marked Future Release
, let's also move this one there.
#49411 was marked as a duplicate.