Limit Search results to a certain custom taxonomy
Viewing 4 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic.
Hi,
I am looking to limit the search results to a custom taxonomy based on user input, any code to work it out.
add_action( WPSOLR_Events::WPSOLR_FILTER_UPDATE_WPSOLR_QUERY, 'limit_taxonomy_search', 10, 1 );
function limit_taxonomy_search( WPSOLR_Query $wpsolr_query ) {
if ( 'test' === $current_keywords ) {
// set taxonomy restriction to current search results
}
}
Okay, how can I pass on regex as a search query to match titles only, when the query matches a specific word..
Currently, the search is happening across the title and content(custom fields), But wanted to limit to title for specific query.
add_action( WPSOLR_Events::WPSOLR_FILTER_UPDATE_WPSOLR_QUERY, 'update_query_existing', 10, 1 );
function update_query_existing( WPSOLR_Query $wpsolr_query ) {
if ( 'test' === $current_keywords ) {
if (preg_match('/^X-[a-zA-Z-]+/', $post_title)) { // checking if this condition matches, then return those results
return the posts matching the above regex;
}
}
}
You must be logged in to reply to this topic.