Maybe you can try adding your condition directly in the query string, using something like this
function wpse_29570_where_filter($where){
global $wpdb;
if( is_search() ) {
$search= get_query_var('s');
$query=$wpdb->prepare("SELECT user_id FROM $wpdb->usermeta WHERE ( meta_key='first_name' AND meta_value LIKE '%%%s%%' ) or ( meta_key='last_name' AND meta_value LIKE '%%%s%%' )", $search ,$search);
$authorID= $wpdb->get_var( $query );
if($authorID){
$where = " AND ( wp_posts.post_author = {$authorID} ) ";
}
}
return $where;
}
add_filter('posts_where','wpse_29570_where_filter');
Related Posts:
- How to redirect to post if search results only returns one post
- Use author author display name in permalink structure for pages and posts
- paginate_links() don’t properly work in search.php?
- Filter the query ONLY for the search results page
- Add admin bar link to edit author
- Extending the site search to include a single custom field
- Modify search function in WordPress (TwentyTwelve)
- How to customize search result page title?
- Authors details such as social media links, emails etc → Is this Meta or something else?
- Display the number of user comments
- Display WordPress Search
- Search user metadata with checkboxes via ajax (almost working)
- Hide Author.php template from specific user role
- Searching for content post
- How to automatically remove links from WordPress Biographical Info?
- changing behaviour of get_search_form
- Commenter should see only his comments in wordpress
- Allow Post Author to be 0 on Update
- Search filter by Post title OR Meta Title Value [duplicate]
- wp-comment author- url +, email filter hook
- check if author has published posts in custom post type, then send mail
- Using wp_redirect and .htaccess to re-route searches (and pass along the remaining GET vars)
- paginate_links() don’t properly work in search.php?
- Author Date Function not working as expected [duplicate]
- Include the post type before the title of search results
- How to rewrite wordpress search to work on specific category
- Disabling Author Page only for subscribers
- two search forms on the same page
- search form leads to 404
- Custom function for search form
- If no author posts, echo out some text
- WordPress: Highlight search result exact matches
- Get post_author email for Zapier Integration
- Author social media aren’t shown on the page
- Limiting WordPress Search function : Custom build
- How To Display Author Popup on Entry Meta (Genesis Framework)?
- More than one search results page template for two searches on site
- How do i create a search option for pdf’s only
- Form output outside of container
- Author Page User id in functions.php for non login user
- Limit Number of Posts on Blog Category Page Throwing 404 Error on Paginated Pages
- Author info does not show up when author has no posts
- us states dropdown function and echo in theme template files
- Pagination in Search result
- Show the online status of the current post’s author
- Make WordPress search for only this tags or exclude certain tags from search [duplicate]
- child_of not working while searching
- Search Woocommerce product titles only
- How to Insert A List of Posts in A Category Written by the Author into the Author Archive
- Custom Post Type Search
- How to add user_registered time in human_time_diff() wordpress
- Add image size if page template
- How to load parent_theme functions.php before child_theme?
- How to use the do_action () with parameter
- TinyMCE custom styles remove class when switching styles
- Notify users whenever a new post is published based on their preference
- syntax for remove_filter in parent theme with class
- Remove Header and Footer in iframe
- Can I remove the Rich Text box editor for a specific post?
- Redirect if not logged in?
- How to set global variables in template page?
- Setting featured image with function, 1 part not working
- Best way to programatically add “rel” attributes to page and post images
- Comments to only be seen by their author
- Remove function or filter
- options.php problem – data not saved
- Filtering posts by category name based on page’s slug
- adding custom classes for tables
- Load parent theme files before child theme functions.php
- CSS for menu item added via functions.php
- Default Gallery Edit/Template Editable?
- Warning: call_user_func_array() expects parameter 1 to be a valid callback, function ‘greenday_head’ not found or invalid function name
- How to validate this deprecated function
- How can I modify all existing tags while keeping the urls themselves?
- Scripts not appending to element in AJAX call – why?
- Trigger a custom function when option are saved in admin area
- Functions.php – Cannot Modify Header Information SOLVED [closed]
- How would I add “edit profile” and “blog post” functions to front-end?
- shortcode help require
- How can I add a filter for specific categories on functions.php?
- Custom editor color palette colors are not appearing in the editor
- echo custom fields with AJAX
- wordpress get_post_meta give only first value
- Using multiple line variable inside a function?
- Determine if, within a post, you are on page 2 or greater – WordPress documentation circular
- Wp-query Order By problem
- Compare meta key to current date in pre get post
- Protect get_query_var from manual input in url
- Shortcode to get featured image of specific id post
- Problem with WordPress output text (‘esc_html’ & ‘wp_richedit_pre’)
- Get slug of current category in functions.php
- removing description tabs – single product page – breaks footer
- How set a while with a function
- How to add a cron job in my functions.php
- Trying to Add a LEFT Sidebar?
- Login functions
- Highlight only current on single pages
- Additional folder where will Media Library look for files
- How do I add schema markup to individual WordPress posts without using plugins?
- Call wordpress function through functions.php when pressing menu