Hi there!
wpss_search_query_args
passes its values straight through to WP_Query
, so you can use any argument that it supports, including post type parameters.
So I’d filter wpss_search_query_args
, check which page you’re on, and pass that as the post type parameter.
Hope that helps,
Konstantin
Hi Konstantin,
I tried to use the wpss_search_query_args
filter to exclude specific pages using the post__not_in
argument, but can’t get it to work properly. Could you please give more details on the filter function?
Would you mind posting your callback function here? As is, I don’t have too much to work with 🙂
post__not_in
should be an array of post ids, is that how you have it?
Here is the function I try to use:
function florist_searchsuggest_filter( $query ) {
$query = array( 'post_type' => 'any', 'post__not_in' => array( 566,1685 ) );
return $query;
}
add_filter( 'wpss_search_query_args', 'florist_searchsuggest_filter' );
When searching, it now gives me always the same results.
Ah, yeah that callback overwrites the default arguments, including the search term. You’d want to merge your parameters with the existing ones, kind of like this:
function florist_searchsuggest_filter( $query ) {
return wp_parse_args( array(
'post_type' => 'any',
'post__not_in' => array( 566,1685 ),
), $query );
}
add_filter( 'wpss_search_query_args', 'florist_searchsuggest_filter' );
Konstantin
Hi Konstantin, that did it. Now it works. Thank you so much.