Save the user IDs found in the first query, as an array, before executing the second query.
Then use that array in the exclude
value, in the second query args and then run it.
UPDATE
How to put the IDs from the first query into an array, to be used in the second query.
You didn’t use the fields
parameter, hence the query returns everything it finds about users (all
(default) Returns an array of WP_User objects)
// Put the found user IDs in an array, after executing the first user query
$exclude = array();
foreach ( $search_query->results as $user ) {
$exclude[] = $user->ID;
}
Now you can successfully use $exclude
as the value of the parameter 'exclude'
, as you did, in the second query.
Related Posts:
- WP Query with custom Shortcode
- meta_query search names when they have middle initials
- How to correctly submit a search form and display the result in an independent page
- Genesis – Customize search form
- How to search display_name column when using WP_User_Query
- How to order WP_User_Query results to match the order of an array of user IDs?
- WP User Query with search columns and meta query
- How to exclude pages from the search results
- Modifying widget search box
- What is the most efficient way to search users by their display name?
- How to make an meta_query optional?
- Rewriting search and pagination base
- How to update single value in multi dimensional Post Meta?
- Easy way to process search results before displaying
- How to find objects by terms
- How to create a WP_Query to search the Title or Tag?
- How can i display 3 post types in same page?
- How to get user by display_name with WP_User_Query
- Adjust the results quantity for Search Results page pagination
- How to block specific keywords from searching on WordPress?
- How to get a list of all users registered before a given date?
- Modern Tribe Calendar wp-query with meta query not working at all
- How do I get images (with a thumbnail preview) to show in search results?
- WP_User_Query order by meta_key that is an array
- Sortable admin column for one meta key with three possible meta values
- Enhanced WordPress Search
- How to display custom field on homepage
- Can an array be used as a meta_query value?
- How do I dynamically generate args for wp_query?
- List of posts by day of the week
- Add relevant tag to search results
- Can I use HTTP POSTs? Is there a better alternative?
- Use wp_get_recent_posts with search term
- If search results empty then execute certain code
- Count the number of times the search form template gets included on a page
- have_posts() execution failure
- esc_url returns incorrect URL
- How to do multiple searches (with logical OR) in WP_Query in hook pre_get_posts?
- Change Navigation Bar based on logged in or not
- Can’t search posts using WP_QUERY inside AJAX Function
- Only show search results with if current date is between two dates?
- WordPress pagination not working with search page
- Input type search in Menu
- How to make a search button that will search my website?
- WordPress Search Results for Multiple Post Types
- Advanced Meta Query for Large Calendar Website (12k+ posts) (175k+ wp_postmeta rows)
- Customising the search function?
- WP_Query Check if post has one or more attached medias
- How to add seperate classes to no-search-result and found-search-result pages on wordrpess search – is_search()
- Custom search results page not working with empty search
- WordPress default Search function inconsistent in WooCommerce Product Titles
- Save Search System
- Seach custom post type posts only by meta fields?
- Get users that likes the post
- Two queries for a WP_User_Query search work perfectly apart, but not together
- Search not showing all results
- Autocomplete search box
- search suggest – filter post type
- Custom query, checking values of multiple meta keys
- Archive post by meta value + 24hours
- edit search.php to include subdomain posts
- Search Query: how to construct a search string from two select elements?
- Can anyone offer any help with this function?
- get_users meta_query: REGEXP not working for matching new lines
- Is it possible to retrieve all posts with a certain value for metadata?
- Grouping posts by a custom meta value
- Omit custom post type from wp-sitemap.xml based on meta key using wp_sitemaps_posts_query_args
- Search WordPress using static html page
- Exclude posts with specific metadata from search?
- Normal PHP array for exclude section of WordPress query?
- Use Tags to initiate Search
- Search form does not work in my website
- How to remove the message ‘We could not find any results for your search’ without changing template files and without adding posts/pages?
- WP_Query: getting posts where custom field exists
- Form search query – displaying ACF “Post Object” field as results
- User Meta Value not echoing despite Var_Dump Showing correct string
- How to hide posts of a specific custom category in WordPress?
- Undefined offset: 0-wp-includes/meta.php:488 -Melding
- Passing an array into WP_Query as a variable
- List post by title length
- WordPress meta_query >= &
- How do I query a single data value from the wp_metadata table?
- Searching Posts Programmatically in a WordPress Plugin
- Search only working on front page (index) , not working on other pages
- Live search from database table
- WordPress Search
- WordPress pagination not working in search result page
- Search page results conflicting logic – Search result caching?
- Search.php gets metadata from first post
- search and add in wordpress content
- How can I modify this code to make the search box include tags and meta
- Validate search against a list of codes in wordpress
- Free search and custom taxonomy query not providing the same result
- search.php to search only the post title
- WordPress get last inserted user id
- Isn’t Returning Value While Using SELECT COUNT(*) FROM {$wpdb->prefix}
- How to sort WooCommerce products page by latest in-stock items first?
- Display WordPress search results based on the selected Sub-Category
- WordPress Search Ajax + Isotope + InfiniteScroll
- how can i include post meta in search result