-
Search Results
-
Hi there
I have search set up which allows the user to search one or both custom post types (ie. shops and events). They can also choose to search by shop category or event category.
I’m using the code below to add an additional option to the event category select box which works fine IF they select Event as the custom post type to search, however, if they don’t specifically select a custom post type to search (ie. are searching on BOTH types) then no results are returned.
Note: I’m using shortcodes to create the page ie.
[searchandfilter id=”13752″]
[searchandfilter id=”13752″ show=”results”]The page loads fine initially, showing all 600 records, but as soon as I run a search without selecting a post type, no results are found… and even clicking “Reset” the query has no effect.
Any suggestions would be very gratefully received.
function edit_event_categories($input_object, $sfid) { if(($input_object['name']!='_sft_ecategory')||($input_object['type']!='select')) { return $input_object; } if(!isset($input_object['options'])) { return $input_object; } //create a new option we want to add $new_last_option = new StdClass(); $new_last_option->value = "99"; $new_last_option->label = "Weekend"; //add a brand new option to the bottom array_push($input_object['options'], $new_last_option); return $input_object; } add_filter('sf_input_object_pre', 'edit_event_categories', 10, 2);
Topic: Author field too big to load
The Problem: I need to load an author dropdown on the filter with just the Editors
I have a Filter for my site, with several fields, one of them is Author, but the website has more than 15.000 users registered and get a timeout error every time the field is enabled.
I’ve tried this to re write the author field with a more manageable amount of users (only the Editors) but with no luck the idea was to remove all content from
_sf_author
and replace it with the editors`
function filter_authors($input_object, $sfid)
{
if (($input_object[‘name’] != ‘_sf_author’) || ($input_object[‘type’] != ‘select’)) {
return $input_object;
}unset($input_object[‘options’]);
$input_object[‘options’] = array();// Generate first array option (default)
$first_option = new StdClass();
$first_option->value = ”;
$first_option->label = ‘All Authors’;//attributes
$first_option->attributes = array(
‘title’ => ‘All Authors’,
);array_push($input_object[‘options’], $first_option);
//change classes & attributes of the field
$input_object[‘attributes’][‘class’] = ‘user_filter’;
$input_object[‘attributes’][‘title’] = ‘Authors’;//add/override prefix & postfix to the field
$input_object[‘prefix’] = “Filter by Author”;//Check if options variable exists
if (!isset($input_object[‘options’])) {
return $input_object;
}//Create new users array
$args = array(
‘role’ => ‘editor’,
‘order’ => ‘ASC’,
‘orderby’ => ‘display_name’,
);// Create the WP_User_Query object
$wp_user_query = new WP_User_Query($args);
$authors = $wp_user_query->get_results();
foreach ($authors as $author) {
// get all the user’s data
$author_info = get_userdata($author->ID);
//create new options with user values
$new_option = new StdClass();
$new_option->value = $author_info->user_login;
$new_option->label = $author_info->first_name . ‘ ‘ . $author_info->last_name;//attributes
$new_option->attributes = array(
‘title’ => $author_info->user_login,
);
array_push($input_object[‘options’], $new_option);
}
return $input_object;
}
// add_filter(‘sf_input_object_pre’, ‘filter_authors’, 10, 2);
`
Using this approach i change a meta field and filled it with the Editors data, but then the post request was send as_sfm_editors
and not_sf_author
and i couldn’t find a way to replace this request for the one i needed.Also tried building my own query accessing the search data and using the hook
sf_results_url
to change the url, but i cannot change the search query with it.I’m running out of ideas, appreciate your time to check my issue and any new ideas on how to solve it.