You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If you include a custom field value in indexing options, it's easy assume this would cause the document to appear in matching search results:
However, getting the document to appear in search results also requires some code monkery:
<?php
/**
* Tell WordPress to also look in the 'search_keywords' post meta for search results.
* By default, this will be title AND post meta, which we filter to OR below.
*/
add_action( 'pre_get_posts', function( $query ) {
if ( $query->is_search() && $query->is_main_query() ) {
$query->set( 'meta_query', array(
array(
'key' => 'search_keywords',
'value' => $query->get( 's' ),
'compare' => 'LIKE',
),
) );
}
});
/**
* Filter the title AND post meta query to be title OR post meta
*/
add_filter( 'solr_select_query', function( $query ){
$query['query'] = str_replace( 'AND((search_keywords_str:', 'OR((search_keywords_str:', $query['query'] );
return $query;
});
This should be way more intuitive.
The text was updated successfully, but these errors were encountered:
If you include a custom field value in indexing options, it's easy assume this would cause the document to appear in matching search results:
However, getting the document to appear in search results also requires some code monkery:
This should be way more intuitive.
The text was updated successfully, but these errors were encountered: