I’m using WP_Query with “s” parameter, but it search all the fields in a post, and I only want to search the title in the post only. Not sure what is the proper way to do it?
$args = array(
's' => $_POST['k'],
'post_type' => 'my_post',
"nopaging"=>true,
'meta_query' => array(
)
);
$my_query = new WP_Query($args);
We need to add filter to wordpress “posts_search”.
Adding the following code to your active themeâs functions.php file will restrict WordPress search results to page and post titles only.
//Limit Search to Post Titles Only
One interesting thing. If you want to work this on products you should use
get_product_search_form
hook.In this way, the results should be given only from searching in Titles.