Search by title only | WordPress.org

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;
}

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer