I’ve tried some snippets I found to limit the search by title on any situation but it doesn’t work… when I search for ROSE it also loads products that have ROSE in the description… how can I stop that and just limit the search by title? This is what I tried but it didn’t work:
add_filter( 'posts_where', 'my_title_filter', 10, 2 );
$latest_post_ids = new WP_Query( $args );
remove_filter( 'posts_where', 'my_title_filter' );
function title_filter( $where, &$wp_query ) {
global $wpdb;
if ( $search_term = $wp_query->get( 'search_post_title' ) ) {
$where .= ' AND ' . $wpdb->posts . '.post_title LIKE \'%' . $wpdb->esc_like( $search_term ) . '%\'';
}
return $where;
}