Hi, one small issue left. I am using [wpv-found-count] shortcode to display the number of posts inside the Parent term (including child terms), but it's displaying a wrong count. why?
Hello and thank you for contacting the Toolset support.
I am not really sure to understand the issue, can you elaborate more? Where the shortcode is being used? Where can we see the results on the frontend? What counts are wrong and what values would you expect?
If you would like to allow me temporary access to your site to check this closer, our next reply will be private to let you share credentials safely. ** Make a database backup before sharing credentials. **
Ok. Let me explain to you with example.
If you go to hidden link (i.e. course archive created with a view suggested by you in https://toolset.com/forums/topic/selective-taxonomy-view/#post-1814669), you will see parent category courses along with the child categories. See screenshot_1. The red squared things are the number of courses (which is wrong).
Now say for example we enter a Parent Taxonomy archive called 'Business & Entrepreneurship Courses' at hidden link. Here you can see the red arrowed figure which is the number of courses under the parent category (this is correct). The number is generated with the shortcode called '[wpv-found-count]'.
Now, I understand why you are getting (1) as a result. It is expected, as it will be pulled for its parent view(Art and Design) because you have passed a term(One term) to the view.
If you want to get the number of posts for this taxonomy term, use the wpv-taxonomy-post-count shortcode.
My apologies for the late reply, but I do not work on Wednesdays and Thursdays.
From what I understand so far, you are looking to get the number of posts on a taxonomy term and its children. For example, the course "Public Speaking", that is assigned to "Professional Development" under "Business & Entrepreneurship" should appear in the count of both terms "Business & Entrepreneurship"(the parent) and "Professional Development"(the child), right?
This is not possible, by default, in Toolset or in WordPress queries.
WordPress only keeps track of the posts that are assigned to a term, it does not count the number of posts of children terms.
So, to get the desired count, for example, 18 posts for the "Business & Entrepreneurship" category, you will have to choose between two solutions:
- Optimal solution: Assign each post to a term and all its parent terms. For example, update the course "Public Speaking" and assign both terms to it ("Professional Development" and "Business & Entrepreneurship").
- Heavy solution: Implement a custom shortcode that will calculate the correct number of posts from the current term and its children. Check this StackOverflow reply, and adapt it to be used in a shortcode https://wordpress.stackexchange.com/a/117092
I hope this answers your question. Let me know if you need further assistance.
I drafted the following code and tested it and it seems to work. This shortcode will need two arguments, the taxonomy slug, and the taxonomy term ID. Check this example for categories(slug: category):