Skip Navigation

[Resolved] Search with checkbox parameter not working

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

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9: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/Karachi (GMT+05:00)

This topic contains 6 replies, has 3 voices.

Last updated by simon 3 years, 6 months ago.

Assisted by: Waqar.

Author
Posts
#1805485
Suche-Präsentationen-hunde-urlaub-net.png
Edit-Group-‹-hunde-urlaub-net-—-WordPress.png

I have a search view with filters on checkbox values, that is no longer working, unfortunately we didn't spot when it stopped working , it could have been several versions of Views ago.

I have a checkbox with a value of 0 or 1 (unselected/selected) - field definition attached.
This is displayed on the search form as a checkbox (attached).
If I select the checkbox on the search form, then no results are returned.
I can see in the search URL that the parameter supplied is in the following format:

special-wellness-status[]=1

If I change the parameter to

special-wellness-status=1

Then the search works correctly.

The search filter shortcode contains the following:

[wpv-control field="special-wellness-status" url_param="special-wellness-status" type="checkboxes" values="1" display_values="Wellness"]

If I change the type parameter above from type="checkboxes" to type="checkbox", then the control on the search form changes to a select (not useful).

How can I set the wpv-control to display a checkbox and apply a filter without an empty array, or alternatively set the array values correctly?

I'm using legacy views 3.2.1

#1805585

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+01:00)

Something doesn't add up in your description above.

The search filter is for a field "special-wellness-status", but the checkbox custom field from your screenshot is "special-wellness-active".

Also the filter control is inserted with the shortcode wpv-control, and I would expect it to be using wpv-control-postmeta for a custom field or wpv-control-post-taxonomy for a taxonomy, perhaps this is an old site.

I suggest you delete the filter altogether and insert it again using the GUI and it should insert the correct shortcode for the correct field and I would expect it to work as intended. If it doesn't, let us know.

(To delete the filter you should delete the markup for that filter from the search and pagination editor as well as deleting the associated Query Filter. If you don't see the Query Filter section, go to the Screen Options tab at the top of the page and make sure it is enabled.)

#1806175
Edit-Group-‹-hunde-urlaub-net-—-WordPress (1).png

Hi Nigel,
Well spotted!
Yes, you are quite right, the field in question is special-wellness-status - this is a select (see attached). I think the view is about 4 years old - I deleted the filter as you suggested and created a new one.

[wpv-control-postmeta type="checkboxes" field="wpcf-special-wellness-status" source="custom" url_param="wpv-wpcf-special-wellness-status" values="1" display_values="Wellness"]

This does look as though it should return the value we want: Special wellness status is a number greater than or equal URL_PARAM(wpv-wpcf-special-wellness-status)

We have a single checkbox on the page, which is exactly what we want.

In this case we are interested in returning any post with a value of 1 or 2 for the field.

When I submit search it returns no values. The url parameter looks like : wpv-wpcf-special-wellness-status%5B%5D=1
If I remove the square brackets

wpv-wpcf-special-wellness-status=1

then I do get the correct posts returned

#1806741

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

query-filter-settings.png

Hi,

Thanks for writing back.

During troubleshooting with the exact same field definition and the "wpv-control-postmeta" field shortcode, I couldn't reproduce the issue.

My view shows the correct results with the square brackets, i.e. "wpv-wpcf-special-wellness-status%5B%5D=1".

Can you please make sure that the query filter for the field is set as shown in the attached screenshot?

In case the issue still persists, you're welcome to share temporary admin login details, along with the link to a page where this view can be seen.

Note: I've set your next reply as private.

regards,
Waqar

#1814153
Edit-View-‹-hunde-urlaub-net-—-WordPress.png

Hey Waqar,
Thanks for trying to reproduce this. If I set my filter to 'number is equal to' then yes it does work. But that isn't what had setup originally. So here are the key points:
The filter control on the page is a checkbox with a value of 1 if selected.
The post meta field we are filtering on is a select with the values 0,1,2
We want to return posts where the post meta = 1 or 2
The filter we are using is:
The field Special wellness status is a number that is greater than or equal the following: URL parameter wpv-wpcf-special-wellness-status
So when the checkbox is selected and has a value of 1, then we should return posts with the select value set to 1 or 2

Waqar - I'm happy to give you access to the site. If you could try and reproduce the filter as I have described and it works, I'd be very happy to let you play - I think you can

#1816413

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Thanks for writing back and for sharing further details.

I was able to reproduce this behaviour on my test website and for this very specific requirement, you can modify the view's query, using the "wpv_filter_query".
( ref: https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query )

Example:


add_filter( 'wpv_filter_query', 'filter_custom_view_query', 1000 , 3 );
function filter_custom_view_query( $query_args, $view_settings ) {
	if ( !is_admin() && ( isset($view_settings['view_id']) && $view_settings['view_id'] == 12345) ) {
		if( (!empty($query_args['meta_query'])) ) {
			for ($i=0; $i < (count($query_args['meta_query'])-1) ; $i++) { 
				if ($query_args['meta_query'][$i]['key'] == 'wpcf-special-wellness-status') {
					$query_args['meta_query'][$i]['value'] = $query_args['meta_query'][$i]['value'][0];
					$query_args['meta_query'][$i]['compare'] = '>=';
				}
			}
		}
	}
	return $query_args;
}

Note: you'll replace "12345", with the actual ID of the view.

I hope this helps.

#1825177

Many thanks Waqar - that worked perfectly

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.