Skip Navigation

[Resolved] Preset value of Taxonomy filter dropdown

This thread is resolved. Here is a description of the problem and solution.

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 replies, has 2 voices.

Last updated by davidS-53 1 year, 12 months ago.

Assigned support staff: Luo Yang.

Author
Posts
#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: English (English ) Chinese (Simplified) (简体中文 )

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!