This website uses cookies to personalize your experience. By using this website you agree to our cookie policy.

Reply To: Custom field in search settings to appear dynamically

Home Forums Product Support Forums Ajax Search Pro for WordPress Support Custom field in search settings to appear dynamically Reply To: Custom field in search settings to appear dynamically

#28751
Ernest MarcinkoErnest Marcinko
Keymaster

Hi,

Well. not exactly but you can ignore products that are not in stock, please check this tutorial

Removing filter values is a bit more difficult, but doable programmatically via the frontend filters API.

This could be a good code skeleton to start with. All you need to implement is to get the custom field values as an array into the $exclude variable, which you want to remove from the filter, the rest should do the code itself.

add_filter('asp_pre_get_front_filters', 'asp_change_a_filter', 10, 2);
function asp_change_a_filter($filters, $type) {
    // Enter the custom field name
    $field = 'custom_field_name';
    // Get the custom field values to exclude from the filter
    $exclude = array('value1', 'value2');

    foreach ($filters as $k => $filter) {
        if ( $filter->type() == 'custom_field' && $filter->data['field'] == $field ) {
            $filter->remove($exclude);
        }
    }
    return $filters;
}