Skip Navigation

[Resolved] [wpv-taxonomy-post-count] fails only on certain taxonomy term values

This support ticket is created 4 years, 1 month ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 2 replies, has 2 voices.

Last updated by martinE-4 4 years, 1 month ago.

Assisted by: Minesh.

Author
Posts
#1547657

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.

#1547777

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

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

#1548659

My issue is resolved now. Thank you!

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.