Home › Forums › Product Support Forums › Ajax Search Pro for WordPress Support › Frontend Search Settings: Any post type › Reply To: Frontend Search Settings: Any post type
In theory, maybe by adding “fake” filters to the front-end with any labels you choose, then processing them during the query arguments filter could actually work.
So for example:
add_filter('asp_pre_get_front_filters', 'asp_add_a_filter', 10, 2);
function asp_add_a_filter($filters, $type) {
foreach ($filters as $k => &$filter) {
if ( $filter->type() == 'post_type' ) {
$filter->add(array(
'label' => 'My Post Type',
'selected' => false,
'value' => 'my_post_type'
));
}
}
return $filters;
}
This should add an additional filter to a post type filter with a label “My post Type” and value “my_post_type”. When this is selected, it is passed to the query arguments.
add_filter("asp_query_args", "asp_query_args_change", 10, 2);
function asp_query_args_change($args, $search_id) {
// The my_post_type was selected
if ( in_array('my_post_type', $args['post_type']) ) {
$args['post_type'] = array('post', 'page', 'other_post_type');
}
return $args;
}
This then detects if the ‘my_post_type’ was selected, and changes the post type arguments to whatever you need.
In theory this should work, but I honestly don’t recall if there is any existence check before or after the query arguments for post types – in which case this can be an issue, and probably will not work.