Skip Navigation

[Resolved] Default View Filter Dropdown Value

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)

This topic contains 3 replies, has 2 voices.

Last updated by Minesh 4 months, 1 week ago.

Assisted by: Minesh.

Author
Posts
#2707956

Tell us what you are trying to do?

I would like a default value selected for a dropdown filter.

E.g. on the below link. I would like "Transnational" to be selected by default / on load.

What is the link to your site?

hidden link

#2707971

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

Can you please check now:
- hidden link

I've added the following code to your view's "Search and Pagination" section JS editor:
=> hidden link

jQuery(document).ready(function($) {
jQuery("select[name^='wpv-country'] option[value='transnational']").attr("selected","selected").trigger('change');;
});

Can you please confirm it works as expected.

#2707990

Hi Minesh,

generally it works but only is applied after initially all results are shown.

Can it be done such that is is applied on initial load. If not could the loading indicator be shown until it refreshes ?

Thank You

#2708082

Minesh
Supporter

Languages: English (English )

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

Can you please check now: hidden link

I've added the following code to "Custom Code" section with code snippet "toolset-custom-code":
- hidden link

add_filter('wpv_filter_query', 'wpv_prefilter_with_taxonomy_term', 99, 3);
function wpv_prefilter_with_taxonomy_term ( $query_args, $view_settings, $view_id ) {
   
     if( $view_id == 17009 and ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX )  ) {
          
	
        $query_args['tax_query'][] = array(
            array(
                'taxonomy' => 'country',
                'field'           => 'slug',
                'terms'        => 'transnational'
            )
        );
          
          
    }
    return $query_args;
}

Also - I've added the following code to your view's "Search and Pagination" section JS editor:
=> hidden link

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

Can you please confirm it works as expected.