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
- Include posts under a custom taxonomy in author.php
- Exclude in search post and include only 3 pages
- Include bbPress topics and replies in WordPress search results?
- Missing feature image link function
- What’s the difference between home_url() and site_url()
- Remove “Category:”, “Tag:”, “Author:” from the_archive_title
- get_template_directory_uri pointing to parent theme not child theme
- How to customize the_archive_title()?
- remove empty paragraphs from the_content?
- What is the “with_front” rewrite key?
- Why use if function_exists?
- How to override parent functions in child themes?
- wp_enqueue_script was called incorrectly
- Add multiple custom fields to the general settings page
- Ajax call always returns 0
- 400 bad request on admin-ajax.php only using wp_enqueue_scripts action hook
- How long does a deprecated function live in core?
- Solution to render Shortcodes in Admin Editor
- How to add a data attribute to a WordPress menu item
- What’s the difference between esc_html, esc_attr, esc_html_e, and so on?
- remove_action on after_setup_theme not working from child theme
- plugins_url vs plugin_dir_url
- Remove type attribute from script and style tags added by WordPress
- How to run a function every 5 minutes?
- Best way of passing PHP variable between partials?
- Upload Multiple Files With media_handle_upload
- How to display custom field in woocommerce orders in admin panel?
- Adding fields to the “Add New User” screen in the dashboard
- Issues with title-tag and document_title_parts
- How do I get the current edit page ID in the admin?
- How to check if a user exists by a given id
- Why isn’t is_page working when I put it in the functions.php file?
- Add tags to the section via functions.php
- Add image size if page template
- How to create a custom order status in woocommerce!
- Remove Actions/Filters added via Anonymous Functions
- Adding a second email address to a completed order in WooCommerce [closed]
- How to load parent_theme functions.php before child_theme?
- How to load scripts/styles specific for a page
- Programatically add options to “add new” custom field dropdown
- Is there any global functions.php file which works for any theme?
- Excluding iPad from wp_is_mobile
- When should you, and when should you not, use wp_list_pluck()?
- Get the ID of the page a menu item links to?
- Add container to nav_menu sub menu
- Difference between the_permalink() and get_permalink() function
- What’s the difference between WordPress random_int() and PHP built-in function random_int()?
- Child theme – Overriding ‘require_once’ in functions.php
- Link to user’s profile settings page?