I have a view with a taxonomy filter which works fine on my custom taxonomy 'asc' except the [wpv-taxonomy-post-count] fails on certain taxonomy term values showing only a value of 1 on 'Research Areas' and 'Field Studies', when actually the real number of posts with that taxonomy term value is greater (see links below).
The view has a limit of 12 per page. It is used in the WordPress archive created in toolset of 'Archive2 for ASC'. The code is used in a shortcode block in the editor:
[wpv-taxonomy-post-count] posts found.
[wpv-taxonomy-post-count] fails at (no browser errors): hidden link (only counts 1 of 12 posts) hidden link (only counts 1 of 19 posts)
and is successful at all other ‘asc' taxonomy term values e.g.: hidden link (counts 4 of 4 posts) hidden link (counts 3 of 3 posts) hidden link (counts 14 of 14 posts)
I will give you the debug credentials below to the staging site.
Hello. Thank you for contacting the Toolset support.
I checked and actually the shortcode [wpv-taxonomy-post-count] is displaying the correct value. If you check with your taxonomy the taxonomy term "Field Studies" is having only 1 post.
=> hidden link
The reason why it's displaying the more than 1 post because its also including the child term posts. To exclude the child terms from you are displaying hierarchical taxonomy term archive, you need to use the standard WordPress hook: pre_get_posts
I've added the following code to Custom Code Section offered by Toolset to exclude the child terms:
=> hidden link
function func_exclude_childs_from_tax_archive( $query ) {
if ( !is_admin() && $query->is_main_query() ) {
if (is_tax('asc')) {
$query->tax_query->queries[0]['include_children'] = 0;;
}
}
}
add_action( 'pre_get_posts', 'func_exclude_childs_from_tax_archive');
If you can check now, its displaying the one post and correct post count: hidden link