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
- How to search display_name column when using WP_User_Query
- How to exclude pages from the search results
- What is the most efficient way to search users by their display name?
- Rewriting search and pagination base
- 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 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?
- List of posts by day of the week
- Can I use HTTP POSTs? Is there a better alternative?
- Use wp_get_recent_posts with search term
- have_posts() execution failure
- 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
- Input type search in Menu
- Advanced Meta Query for Large Calendar Website (12k+ posts) (175k+ wp_postmeta rows)
- 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()
- 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
- Can anyone offer any help with this function?
- get_users meta_query: REGEXP not working for matching new lines
- Grouping posts by a custom meta value
- 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
- Undefined offset: 0-wp-includes/meta.php:488 -Melding
- List post by title length
- How do I query a single data value from the wp_metadata table?
- 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
- Free search and custom taxonomy query not providing the same result
- WordPress get last inserted user id
- How to sort WooCommerce products page by latest in-stock items first?
- WordPress Search Ajax + Isotope + InfiniteScroll
- My worpress search page is showing no results
- Replace a single variable with add_filter
- Build A Custom SQL Query for WordPress Search
- Include custom fields in search
- Using a new WP_Query inside the loop
- Change ajax live search results
- Usermeta data unserialize, extract and display in table in WordPress
- Showing search results on a page
- Help me understand how Search function works using dynamic_sidebar()
- What is the correct way to search 3 custom fields only in WordPress?
- Searching a custom WP table and displaying results in an HTML table
- Search only for posts with specific metadata?
- Search function not working
- Filter loop by ‘price’ with meta_query
- My search results are only showing 5 posts?
- WP_query meta_query slow with OR and DATES
- Get meta_query value by user meta array
- How can the searchform.php know if it’s used on a registered sidebar id ‘sidebar-1’ or ‘sidebar-2’?
- How can I include tags in wordpress search without a plugin
- How can you disable search for non-members on your WordPress website.
- Search results template listing all posts
- How to order users alphabetically by name? in plugin UPME
- Search bar for page that searches only particular page IDs
- Limit Search Queries per IP per Day
- Different layout on search page depending on category post
- Make the text field in search form optional
- Search box background on a different page template
- Search through documents folder
- Trying to put a search page on site
- split searchresults into different topics?
- Search result page – display values from the result’s metaboxes
- How to strip/remove all blank spaces at the beginning/end of a search string
- Too many if’s and else if’s ?? – Must be better way [closed]
- The search doesn’t work properly
- How to make WordPress search.php display all strings found on pages or posts
- get second ID from array
- Search custom post type posts only by meta fields?
- Limit a search box by CPT + taxonomies, in only one page