Limit WordPress Search To Post Titles

In this article, you will see how to limit your wordpress search to post titles only.

WordPress version

  • WordPress 3.5

Source Code

$search .= “{$searchand}(($wpdb -> posts.post_title LIKE ‘{$n}{$term}{$n}’) OR ($wpdb -> posts.post_content LIKE ‘{$n}{$term}{$n}’))”;

Remove the OR part (in bold) to make it specific to post title.

$search .= “{$searchand}(($wpdb->posts.post_title LIKE ‘{$n}{$term}{$n}’))”;

Source File

  • Source code is located in wp-includes/query.php.


No comments yet.

Leave a Reply