Startseite › Toolset Professional Support › [Gelöst] Hide posts if their checkbox is checked in a front end view & filter
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 |
---|---|---|---|---|---|---|
- | 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/Hong_Kong (GMT+08:00)
Tags: Custom search, Views plugin
Verwandte Dokumentation:
Dieses Thema enthält 1 Antwort, hat 2 Stimmen.
Zuletzt aktualisiert von Luo Yang vor 4 Jahren, 11 Monaten.
Assistiert von: Luo Yang.
Hi Toolset,
I have a custom field where if a custom post type (Agency) does not have projects, then my data entry guy will check a custom field called "Agency NEVER posts projects" for the custom post type (Agency). This is a simple checkbox.
I want to create a filter on the front end where if this checkbox is checked then the Agencies that "Never post projects" will NOT show up.
Right now I have the filter where the checkbox is marked, then Only Agencies that "Never post Projects" will show up leaving out my desired results where Agencies that do post projects show up in the view.
But I need to have the opposite effect where if this filter is checked then the agencies with the custom field marked will NOT show up in the view.
Please let me know how I can do this and Where I put the code.
Thank you
Hello,
It needs custom codes, for example, add below codes into your theme file "functions.php":
add_filter('wpv_filter_query', function($query, $setting, $view_id){ if($view_id == 123 && isset($_GET['wpv-wpcf-agency-never-posts-projects']) && $_GET['wpv-wpcf-agency-never-posts-projects'] == 1 && isset($query['meta_query'])){ foreach($query['meta_query'] as $k => $v){ if(isset($v['key']) && $v['key'] == 'wpcf-agency-never-posts-projects'){ $query['meta_query'][$k]['compare'] = 'NOT EXISTS'; } } } return $query; }, 10, 3);
Please replace 123 with your view's ID
replace "wpv-wpcf-agency-never-posts-projects" with the specific URL parameter name. By default, you don't need to change it
replace "wpcf-agency-never-posts-projects" with the specific custom checkbox slug. By default, you don't need to change it
More help:
https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query
https://developer.wordpress.org/reference/classes/wp_query/#custom-field-post-meta-parameters