-
Search Results
-
Topic: Apply Filter onload
Hi,
I need to apply a category filter onload rather than showing all categories. I’ve used the below code to set the default to ‘news’ and removed the all option. But it still loads all the posts rather than just the news post on load.
add_filter(‘sf_input_object_pre’, function ($input_object, $sfid)
{
if(($input_object[‘name’]!=’_sft_category’))
{
return $input_object;
}
$input_object[‘defaults’] = array(“news”);
array_shift($input_object[‘options’]);
return $input_object;
} , 10, 2);Topic: No longer searching
All of a sudden the search forms have stopped sorting. The page is here: https://intrepidexposures.com/photo-tours/
Tweaks to code as per previous threads here:
// Search Filter function filter_input_object($input_object, $sfid) { if(($input_object['name'] == '_sfm_workshop_location') || ($input_object['name'] == '_sfm_tour_style') || ($input_object['name'] == '_sfm_tour_leader')) { $new_options = array(); //the options added to this will replace all existing optoins in the field foreach($input_object['options'] as $option) { if ($option->value !== "") { //check to see if the option has a parent $parent_id = wp_get_post_parent_id($option->value); if(!$parent_id) { //then this option does not have a parent, so it must be a parent itself, add it to the new array $option->label = get_the_title($option->value); array_push($new_options, $option); } } } //now we have an array with only parent options in, so simply replace the one in the input object $input_object['options'] = $new_options; } return $input_object; } add_filter('sf_input_object_pre', 'filter_input_object', 10, 2);
Any ideas?