Tell us what you are trying to do?
I'm trying to load the Values under Downtown / Pacific City, so it won't load the whole list from my list of businesses under SECTOR.
Right now visitors still need to click on submit for the Businesses under Downtown / Pacific City to be listed, and it loads all the businesses which is not ideal since we have tons of businesses listed. I need the default loadout to filter it to Downtown / Pacific City once a visitor loads our site.
I split this into another ticket to create a feature request for this, as it seems like a good idea for a Views feature, but I'll try and help you set it up here, which will require some coding.
Because you don't have an empty placeholder in the filter the Downtown / Pacific City option already appears selected, so all that is needed is to use the wpv_filter_query API filter to set that option if no other filter is already chosen.
You can try adding the following code to your site (at Toolset > Settings > Custom Code):
/**
* Set default custom field filter if not already set
*/
function tssupp_filter_query($view_args, $view_settings, $view_id) {
$slug = 'sector';
if (in_array($view_id, array(359))) {
// Edit View ID
$exists = false;
if (isset($view_args['meta_query'])) {
foreach ($view_args['meta_query'] as $key => $meta_query) {
if (isset($meta_query['key']) && $meta_query['key'] == 'wpcf-'.$slug) {
$exists = true;
break;
}
}
}
if (!$exists) {
$view_args['meta_query'][] = array(
'key' => 'wpcf-'.$slug,
'value' => 1,
'type' => 'CHAR',
'compare' => '=',
);
}
}
return $view_args;
}
add_filter('wpv_filter_query', 'tssupp_filter_query', 101, 3);
Check that the slug is correct, and edit the ID of your View.
Do you want to try that and let me know how you get on?
Hi, I just tried to add in the snippet but the portion on the custom code where I insert the code is not showing, it just loads non stop.. any other work around, we can also go with showing nothing to list on page load, then shows the list after the visitors change the values on the search, and clicks in the SEARCH or FIND button on my case.
I'm using OceanWp with elementor, I tried disabling all the plugins and leave the views plugins, but nothing changed, just non stop loading..
That will create a debug.log file in your /wp-content/ directory which you can examine in any text editor. Try visiting the same Code Snippets page again then inspect the log. If you don't find the debug.log file it means it didn't generate any warnings or errors.