Skip Navigation

[Resolved] Pre-selected radio option in filters

This support ticket is created 6 years, 3 months ago. 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.

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

Last updated by Alexanndre Levan 6 years, 2 months ago.

Assisted by: Minesh.

Author
Posts
#1124891

I have filters for my view based on categories setup which work correctly: hidden link

However, currently when you load the page with this view, it displays ALL the results until you choose to filter them. I would like to only show 1 category at a time. The easiest solution I can come up with is to have a specific radio button pre-selected and have the results pre-filtered based on that selection as soon as the page loads.

How would I achieve this?

#1125230

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

Well - in general to prefilter view, you can use views filter hook: wpv_filter_query

For example - something like this:

add_filter('wpv_filter_query', 'func_prefilter_view_results', 99, 3);
function func_prefilter_view_results ( $query_args, $view_settings, $view_id ) {
   
     if( $view_id == 9999) {
          if( !isset($_GET['wpv_view_count'])){ 

        $query_args['tax_query'][] = array(
            array(
                'taxonomy' => 'category',
                'field'           => 'slug',
                'terms'        => 'customer-focus'
            )
        );
    }      
          
    }
    return $query_args;
}

Where:
- Replace 9999 with your original View ID
- Adjust your taxonomy and terms slugs

More info:
=> https://toolset.com/documentation/programmer-reference/views-filters/wpv_filter_query/

#1128507

My issue is resolved now. Thank you!