Tell us what you are trying to do?
I have checkbox costum-fields with several options.
Categorie: checkboxes-auto-verkehr (slug: checkboxes-auto-verkehr)
[ ] checkbox 1
[ ] checkbox 2
[ ] checkbox 3
Categorie: checkboxes-bauen-renovieren (slug: checkboxes-bauen-renovieren)
[ ] checkbox 1
[ ] checkbox 2
[ ] checkbox 3
Now I want to show only one category e.g. "Categorie: checkboxes-auto-verkehr" in a view.
The view should show all posts with a check mark in this category.
I tried several settings in the query filter like:
- Checkboxes - Auto & Verkehr is a string in URL_PARAM(wpv-wpcf-checkboxes-auto-verkehr)
- Checkboxes - Auto & Verkehr is a string in checkbox-1 or Checkboxes - Auto & Verkehr is a string in checkbox-2
The filter settings do not work. I always get all posts from all checkbox-costum-fields (categories) displayed.
Is there any documentation that you are following?
No
Is there a similar example that we can see?
No
What is the link to your site?
hidden link
What am I doing wrong?
Hope you can help me with my issue
Regards,
Jenny
I've tried a little myself and tried to solve the problem with a php script. I've done something similar before with a date filter and it works fine.
But this time it doesn't work. The view (ID = 72) still shows me all results (posts) without filtering.
Here is the php code I'm using:
add_filter('wpv_filter_query', 'wpv_show_prefilter_auto', 99, 3);
function wpv_show_prefilter_auto ( $query_args, $view_settings, $view_id ){
$views = array( 72 );
if( in_array( $view_id, $views) && !isset($_GET['wpv_view_count']) ) {
$query_args['meta_query'][] = array(array(
'key' => 'wpcf-checkboxes-auto-verkehr',
'value' => array( checkbox1 , checkbox2 , checkbox3 ),
'compare' => 'IN',
));
}
return $query_args;
}
Hello and thank you for contacting the Toolset support.
I don't think that the custom PHP code that you have added will help, because the values of a checkboxes field are saved as a serialized array that also contains some Toolset settings information.
On the other hand, when no checkbox is selected, Toolset views will not apply the checkboxes filter and therefore will return all the posts. Once you select one checkbox, the filter will be applied, and the view will return posts that have at least the searched checkboxes value selected.
I understand that you want to have empty results when no checkbox is selected, right? If yes, implement a code similar to this reply https://toolset.com/forums/topic/how-to-make-default-results-blank-for-parametric-search/#post-347797
Note that this previous ticket is about the text search field, you will need to customize the code a bit to handle the checkboxes case.
For the filter, you can keep the one on your screenshot screenshot01.jpg Or you can remove it and add it again in the filter section, which will create the query filter automatically for you.