Wp query show post by author name or post title or post content

I have to create a search query which allows me to filter all posts where author name and post titles or post content has the word from search textbox.

So if i search wordpress it should list all the posts from authors with that word also post who includes it either on their title or content.

Topic posts-where mysql wp-query Wordpress

Category Web


I hope this would do, i have not tested it. Test it on your own risk, but the query related to it very closely.

function kv_get_custom_search_query($search_text){
   global $wpdb;
   $wpdb->get_results( "SELECT * FROM $wpdb->posts WHERE post_title='%$search_text%' OR post_content='%$search_text%' OR post_title='%$search_text%' LEFT JOIN $wpdb->users ON $wpdb->posts.post_author=$wpdb->users.ID AND display_name='%$search_text%'");

}

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.