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.


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%'");

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.