What you are trying to accomplish is not directly possible. ACF only stores the post ID of the post object field. Using WP_User_Query there isn’t any way to look at the title of that post. For this to work that post title would need to be stored in the user meta table.
The above is possible, you would need to create an acf/save_post filter. In this filter if a user is being saved then you would get the post object field and then get the title of the post and store it into another meta_key using update_post_meta(). Then you could use this new meta_key in your search.
The main issue with doing this is that it would not be automatically updated if the post title was changed. This means that you’d need to create another filter that runs every time a post is saved. In this filter you’d need to do a query for all users that have selected the post and then update your new field to hold the correct title.
Your other problem is that you cannot to an “OR” relationship between the standard WP search term and a meta query. It will only return results where the search term is in one of the standard search field AND it is in the meta value. This means the you need to also alter the WHERE clauses of the user query. I don’t have any information on doing this but it would be similar to searching a post where you want to do an OR with the post content or a meta field. I’ve done a quick search but I can’t find anything on how you’d go about doing this. This has come up before here, but I don’t think it was ever resolved https://support.advancedcustomfields.com/forums/topic/extend-backend-user-search-to-custom-user-meta/
Viewing 3 posts - 1 through 3 (of 3 total)
The topic ‘WP_User_Query search with meta_query for Post Object field in user meta data’ is closed to new replies.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users