i have a user_meta for users that them is array like below:
user_saved_posts = [31289,31482,27641]
and i want to get users that their user_meta include an item of an array like below:
goal_posts = [31289,31422,77641,41289,21482,17641]
if user have an item of goal_posts array must returned them.
i use below code but this code worked if i have a value for search in user_meta
$args = [
'meta_query' => [
[
[
'key' => 'saved_posts',
'value' => sprintf(':"%s";', 31289),
'compare' => 'LIKE'
]
]
]
];
get_users($args);
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
I solved my problem in another way(WPDB).
I wrote a query for this purpose like below:
$goal_posts = [31289,31422,77641,41289,21482,17641];
$sql = "SELECT * FROM wp_usermeta WHERE (meta_key = 'saved_posts') AND (";
$sql .= implode(" OR ", $goal_posts);
$sql .= ') GROUP BY user_id';
global $wpdb;
$users = $wpdb->get_results($sql);
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0