Forums › Forums › Search & Filter Pro › "Order terms by Count" does not include count of child terms
- This topic has 3 replies, 2 voices, and was last updated 7 years, 9 months ago by Trevor.
-
Anonymous(Private) March 7, 2017 at 6:08 pm #95327
Hi there.
I have created a search form that filters by a custom taxonomy using checkboxes. I have ticked ‘Display Count’, ‘Hierarchical’ and ‘Include Children in Parents’. I have then gone into the advanced settings and set ‘Order terms by’ to ‘Count’.
The count displays correctly, including posts in child terms, but the ordering of the terms seems to ignore the child terms. For example:
‘Fruits (12)’ has 12 entries
‘Vegetables(6)’ has 6 entries
‘Meats(15)’ has 5 entries and 2 child terms, ‘Red (5)’ and ‘White (5)’They appear in the order you see above, but including its children, ‘Meats’ has more entries than the other terms so it should appear at the top of the list, not the bottom. The count in brackets is correct but the order is not.
Looking forward to hearing from you.
Thank you.
Anonymous(Private) March 8, 2017 at 1:22 pm #95500You mean for the individual posts? In this example, all posts in the ‘Red’ term are marked as ‘Red’ but not as ‘Meat’. I’m sure adding them as ‘Meat’ as well would fix the ordering but as the displayed counts seem to include children, I’d have thought it should be possible to include the children in the ordering too. Forcing the user to add all parent terms whenever they add a child term is not really an option, partly because I can’t guarantee all users will follow this rule and partly because it wouldn’t always make sense.
Here’s an example:
If I’m running a shop website and I label my products with taxonomies, it’s logical to expect that if an item is tagged as ‘red meat’, it should also be tagged as ‘meat’.
However, if I want to tag customers with their interests, someone (let’s say Bob) who is interested in ‘red meat’ may not be at all interested in ‘meat’ in general. Bob’s interest is specific so he would need to be tagged just with ‘red meat’ and not ‘meat’. If I then filtered my customers by ‘meat’, with the ‘Include Children in Parents’ flag switched on, I’d expect to see Bob included in the count in brackets (which currently is working) but I’d also expect ‘meat’ to be in the correct order when the terms are ordered by count.
Essentially, when terms are ordered by count, this should be impossible:
> Fruits (12)
> Vegetables(6)
> Meats(15)
> Red meat (5)
> White meat (5)‘Meats’ should be at the top, even though only 5 posts are directly tagged as ‘meat’, because when you include posts tagged as its children, the count is 15 (as it says correctly in the label).
Trevor(Private) March 8, 2017 at 1:33 pm #95504Right now, by default the plugin only sorts by the count excluding the children. I wonder if it is possible to modify the query using our Edit Query Arguments filter. It should be, if it can be done in general in WordPress.
You might want to do a search in this forum for
sf_edit_query_args orderby
to see if there any code snippets. For example, I found this thread. Not the same question, but it does show another user has used this filter. -
AuthorPosts