Skip Navigation

[Resolved] define search filter custom range

This support ticket is created 2 years, 10 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 23 replies, has 2 voices.

Last updated by Tiit Sau 2 years, 10 months ago.

Assisted by: Minesh.

Author
Posts
#2252211

Well, medium range(15-25) looks pretty good.
In 'small' range lower than 10 are missing and 'large' result is 'No items found'.

#2252251

Minesh
Supporter

Languages: English (English )

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

I checked all the range now and I can see its working.

Here is the modified code added to functions.php file:

add_action('pre_get_posts', 'registration_date_and_today',999,1);
function registration_date_and_today($query){
	
	
	if(is_archive('product') and isset($_REQUEST['search']['dps_general'])){
		

        foreach($_REQUEST['search']['dps_general'] as $k=>$v):
            
			if($v['name'] == 'wpv-wpcf-total-area[]'){
							 
				$range = explode("-",$v['value']);
							
				$meta_query[] = array(
				'relation'=>'AND',
				array(
                'key'     => 'wpcf-total-area', 
                'value'   => $range[0],
				'type' => 'NUMERIC',
                'compare' => '>=',
				),
				array(
                'key'     => 'wpcf-total-area', 
                'value'   => $range[1],
				'type' => 'NUMERIC',
                'compare' => '<=',
				)
				
				);
				
				
                 $query->set('meta_query',$meta_query);			
				
            }
              
        endforeach;
	}
}

Can you please confirm it works as expected: hidden link

#2252263

Minesh, You really did good job. Just couple more things.
Ranges do not work simultaneously, so I changed checkboxes to radios, as they makes more sense for user also in current case. Result was not good. Is there something, I should do after type change?

#2253323

Minesh
Supporter

Languages: English (English )

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

I see on the site you still have checkboxes filter available. I already show you how you can customize the query as it will require more or less custom programming which is beyond the scope of our support policy.

However - I would still really want to help you out but you need to be precise with your requirement. Do you want me to setup a radio button filter instead of checkboxes?

#2253343

Yes, Minesh.
Help me one more time to setup a radio button filter instead of checkboxes.
After setting type to 'radios' filter displays only products with the the first value of range.

Thanks again!

#2253353

Minesh
Supporter

Languages: English (English )

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

Can you please check now. I've adjusted the if condition within the pre_get_posts hook as given under:

if($v['name'] == 'wpv-wpcf-total-area'){

Can you please confirm it works as expected using radio button as well.
=> hidden link

#2253389

Very nice!
I do confirm, filter ranges works as expected using radio buttons.
Before closing this ticket:
Is there a way to choose "show all values for inputs" by type?

#2253391

Minesh
Supporter

Languages: English (English )

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

No - there is no such option. "show all values for inputs" will be applied as globally to all the filters.

#2253393

My issue is resolved now. Thank you!