Skip Navigation

[Résolu] Preset value of Taxonomy filter dropdown

Ce fil est résolu. Voici une description du problème et la solution proposée.

Problem:

Is there some event I need to trigger to get Views to update the displayed results?

Solution:

You can try to modify your JS codes as below:

https://toolset.com/forums/topic/preset-value-of-taxonomy-filter-dropdown/#post-1367151

Relevant Documentation:

https://api.jquery.com/trigger/

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.

This topic contains 2 réponses, has 2 voix.

Last updated by davidS-53 Il y a 1 an et 9 mois.

Assigned support staff: Luo Yang.

Auteur
Publications
#1367007

I have a wordpress archive set up with a taxonomy filter select dropdown named "wpv-product-category". When navigating to the page, I want to preset the taxonomy select option to "household". I have the following JQuery added to the JS of the filter section:

jQuery(document).ready(function($) {
jQuery("select[name^='wpv-product-category'] option[value='household']").attr("selected","selected");
});

It changes the select value just fine, but does not update the results on the page. Is there some event I need to trigger to get Views to update the displayed results?

Thanks for your help.

#1367151

Luo Yang
Supporter

Languages: Anglais (English ) Chinois simplifié (简体中文 )

Timezone: Asia/Hong_Kong (GMT+08:00)

Hello,

I assume you are using AJAX search option: AJAX results update when visitors change any filter values
You can try to modify your JS codes as below:

jQuery(document).ready(function($) {
	jQuery("select[name^='wpv-product-category']").val("household");
	jQuery("select[name^='wpv-product-category']").trigger("change");;
});

More help:
hidden link

#1368237

Works a treat, thanks a lot!