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
- What’s the difference between WordPress random_int() and PHP built-in function random_int()?
- Remove a menu item created by a plugin
- Show Video in Excerpt
- How to fix a theme with page.php Default Template that accidentally deleted?
- Override parent theme function that is not hooked or in the functions.php file
- Theme Demo in live Site
- Removing title from page
- Why isn’t is_page_template() adding a body class?
- Still relevant method of embedding images in WP Theme in 2018
- post to subcategory and parent in wp_insert_post
- Variable if post is sticky in functions.php
- Create a new query in function.php to filter blog posts
- Use third party Library in wordpress
- Creating new blog on multisite programatically without hacks?
- Allowing users to view private posts (pending approval)
- How to get correct URLs in network wide menu (Multisite)?
- Connecting to a 2nd DB gives me no results when querying
- Including php files within template
- The Loop not looping?
- I can’t seem to install Font Awesome locally [closed]
- New custom menu created. how to apply it?
- problem loading stylesheets to wp_head dynamically
- Restrict Search Results to Post Author
- Use Composer Package inside class – Namespacing error
- Update to functions.php not showing in dashboard
- Unable to point the child theme directory even using get_stylesheet_directory()
- Need a method to prevent WP from adding in between my shortcodes
- Change WooCommerce add_to_cart Button Text?
- wp_get_attachment_image_src returns image on main domain, false on subdomain
- Get the alphabetical sorted data with wpdb
- WordPress Check User Role Function (multiple roles)?
- struggling with syntax for the_post_thumbnail();
- Woocommerce Default sorting product by product type
- Adding custom social icons to the social media icon block in the Gutenberg editor?
- Allow user select role in wordpress default registration without plugin
- Display link to category over featured image
- Does hook have an effect on increasing the page load?
- Re-style Login Form Whilst Keeping CSS Separate from Frontend CSS
- Can You Set A Minimum Image Dimension For Resizing Images?
- How to add custom column into custom post, when field is select
- Function image_send_to_editor returns emty title tag
- Integrate WP Tiles into existing loop (index.php) and theme
- Show latest custom post types on dashboard
- Using conditionals, maybe from a DB, to register & enqueue files, for varying pages, in functions.php
- Adding a filter to my posts
- Directing to functions.php the correct way
- comment_post function with js not running
- Animated Accordion [closed]