Sauter la navigation

[Résolu] [wpv-taxonomy-post-count] fails only on certain taxonomy term values

This support ticket is created Il y a 5 années et 2 mois. 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.

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)

Ce sujet contient 2 réponses, a 2 voix.

Dernière mise à jour par martinE-4 Il y a 5 années et 2 mois.

Assisté par: Minesh.

Auteur
Publications
#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):
lien caché (only counts 1 of 12 posts)
lien caché (only counts 1 of 19 posts)

and is successful at all other ‘asc' taxonomy term values e.g.:
lien caché (counts 4 of 4 posts)
lien caché (counts 3 of 3 posts)
lien caché (counts 14 of 14 posts)

I will give you the debug credentials below to the staging site.

#1547777

Minesh
Supporter

Les langues: Anglais (English )

Fuseau horaire: 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.
=> lien caché

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:
=> lien caché

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: lien caché

#1548659

My issue is resolved now. Thank you!