I’ve the next code:
//Alter question to exclude posts which are outdated, or whose class is hidden
operate mts_alter_query($question){
if(($query->get("post_type") === "product" && !is_admin() && !$query->is_singular()) || $query->is_search()){
//$query->set("s", "chelsea");
//Cover outdated posts
$query->set("meta_key", "match-date");
$query->set("meta_value", date("Y-m-d"));
$query->set("meta_compare", ">");
//Cover posts that belong to a hidden class
$hidden_cat_ids = get_hidden_category_ids();
$original_tax_query = $query->get( 'tax_query', [] );
$query->set("tax_query", array(
array(
"taxonomy" => "product_cat",
"area" => "term_id",
"phrases" => $hidden_cat_ids,
"operator" => "NOT IN"
),
$original_tax_query
));
}
}
add_action( 'pre_get_posts', 'mts_alter_query' );
This question alteration works on queries that aren’t from Ajax Search, comparable to merchandise lists or classes pages. However for some cause it does not work on the Ajax Search widget. I am speaking concerning the popup field that seems once you enter the search worth however earlier than you click on submit, and never the precise search web page.
If I uncomment this line: //$query->set("s", "chelsea");
, the search time period “chelsea” will apply and the popup field will present outcomes for “chelsea”. However the remainder of the question nonetheless does not work.