Saltar navegación

[Resuelto] 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 -

Zona horaria del colaborador: Asia/Kolkata (GMT+05:30)

Este tema contiene 3 respuestas, tiene 2 mensajes.

Última actualización por Minesh 1 year, 10 months ago.

Asistido por: Minesh.

Autor
Mensajes
#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?

enlace oculto

#2707971

Minesh
Colaborador

Idiomas: Inglés (English )

Zona horaria: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Can you please check now:
- enlace oculto

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

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
Colaborador

Idiomas: Inglés (English )

Zona horaria: Asia/Kolkata (GMT+05:30)

Can you please check now: enlace oculto

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

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:
=> enlace oculto

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

Can you please confirm it works as expected.