How to Search WP Posts Content on Backend
What Will I Learn?
This tutorial demonstrates a quick way to improve the search results on the backend of WordPress to include the posts with the search query in post content to search results as well.
Requirements:
- Basic CSS & HTML knowledge;
- Basic WordPress knowledge.
Thank you for visiting AMPire.city!
You got lucky! We have no ad to show for you. If you still want to support my work in a different way, please, subscribe to newsletter or become a Patron
Click on the Ad to support my work.
Thank you for visiting AMPire.city!
You got lucky! We have no ad to show for you. If you still want to support my work in a different way, please, subscribe to newsletter or become a Patron
Click on the Ad to support my work.
Thank you for visiting AMPire.city!
You got lucky! We have no ad to show for you. If you still want to support my work in a different way, please, subscribe to newsletter or become a Patron
Click on the Ad to support my work.
Working Code Example
By default, the search results on the edit.php
page in WordPress only show posts that match the search query in the post title. To include post content in the search results, you will need to modify the code in your theme.
Here’s a sample code you can add to your theme’s functions.php
file to include post content in the search results:
function modify_search_query( $query ) {
if ( !is_admin() && $query->is_search )
$query->set( 'post_type', array( 'post', 'page', 'your_post_type' ) );
return $query;
}
add_filter( 'pre_get_posts', 'modify_search_query' );
Thank you for visiting AMPire.city!
You got lucky! We have no ad to show for you. If you still want to support my work in a different way, please, subscribe to newsletter or become a Patron
Click on the Ad to support my work.
This code will modify the default search query in WordPress to include post content in addition to post titles. Note that you may need to adjust the post type to include any custom post types you may have on your site.