Skip Navigation

[Résolu] Custom counter shortcode not updated in views filter

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

Aucun de nos assistants n'est disponible aujourd'hui sur le forum Jeu d'outils. Veuillez créer un ticket, et nous nous le traiterons dès notre prochaine connexion. Merci de votre compréhension.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9: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/Karachi (GMT+05:00)

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

Dernière mise à jour par vimalS Il y a 5 années et 8 mois.

Assisté par: Waqar.

Auteur
Publications
#1213034

Tell us what you are trying to do? Custom counter shortcode not updated in views filter

Is there any documentation that you are following?

Is there a similar example that we can see?

What is the link to your site? lien caché

#1213070

Hi Vimal,

Thank you for waiting.

I've checked your custom shortcode "postcount" and noticed that it is using WordPress' "wp_count_posts" function ( ref: https://codex.wordpress.org/Function_Reference/wp_count_posts ) to get the count of "specialisme" type posts.

Since that function returns the total number of posts from a post type, your shortcode is working as expected to return "2".

I hope this clarifies.

regards,
Waqar

#1213137
Screenshot_17.png

Hi Waqar,

Please check attached screenshot for expected results.

Thanks!!

#1213575

Hi Vimal,

Thanks for writing back and for sharing the screenshot.

If you'll note closely the text "2 specialisaties" can have two possible states:

A. When no specialisatie is selected, it should show the count of "specialisme" type posts, i.e. "X specialisaties"

B. When a specialisatie is selected in the filter field, it should show "1 specialisatie".

To dynamically switch between these two states, you can follow these steps:

1. Update the following content line from:


<span class="sub-title">[wpv-found-count] diensten in [postcount] specialisaties</span>

To:


<span class="sub-title">[wpv-found-count] diensten in <span class="sub-title-multiple">[postcount] specialisaties</span><span class="sub-title-single" style="display: none;">1 specialisatie</span></span>

Note, how the text for both cases is included in separate span tags, but the one for the case B is hidden, at the start.

2. In the "JS editor" tab under the "Zoeken en paginering" section, include the following script:
( screenshot: lien caché )


function updateSpecialisaties() {
	var specialisme = jQuery("div.form-group > select#wpv_control_select_wpcf-related-specialisme").val();
	if (specialisme > 0)
    {
		jQuery("span.sub-title-multiple").hide();
        jQuery("span.sub-title-single").show();
    }
  	else
    {
      	jQuery("span.sub-title-single").hide();
		jQuery("span.sub-title-multiple").show();       
    }	  
}

It will detect the value selected for the specialisatie filter field and will show/hide the specialisatie text, accordingly.

3. Lastly, add "updateSpecialisaties" text in the "zal uitgevoerd worden na het updaten van de resultaten" field, so that script is executed when the results are updated through AJAX.
( screenshot: lien caché )

I hope this helps and for more personalized assistance around custom code, you can consider hiring a professional from our list of recommended contractors:
https://toolset.com/contractors/

regards,
Waqar

#1213642
Screenshot_19.png
Screenshot_20.png
Screenshot_21.png
Screenshot_22.png

Hi Waqar,

"specialisaties" is custom post type and it is not limited to 2 or 1.
Please check attached screenshot for better understanding.

Thanks!!

#1213795

Hi Vimal,

It is clear to me that "specialisaties" is a custom post type and it would make sense to show the total number of posts from that, when specialisaties filter field is not used and the results are showing from all posts.

But the specialisaties filter field can select only "1" specialisatie at a time, as shown in your previous screenshot too:
lien caché

In this context, please check my last message again and let me know if I'm missing something.

regards,
Waqar

#1214046
Screenshot_1.png

Hi Waqar,

Yes, you are right we can select only one specialisatie at a time.
But, as you can see the last search box, in that search box we can search using "diensten" as well.
See attached screenshot.

Thanks!!

#1214135

Hi Vimal,

I can understand the case that your screenshot is showing.

It would be like this when no "specialisatie" is selected from its relevant field, but the searched term's results, fall naturally within a particular "specialisatie".

Strictly technically speaking, the performed search in this case too, is not narrowed down to a particular specialisatie and the results were indeed called from all specialisaties and not any specific ones. So "2 specialisaties" (i.e. the count of all specialisaties posts) is not a wrong/incorrect statement.

But if you'd still like to adjust this statement, you'll need more complex script to detect if the final results are from any specific specialisatie or not.

Customization script like this would be beyond the scope of support that we can provide ( https://toolset.com/toolset-support-policy/ ), but you can hire someone to assist you with this customization, from our list of recommended contractors:
https://toolset.com/contractors/

regards,
Waqar

#1214524

My issue is resolved now. Thank you!