Question

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);
Was it helpful?

Solution

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);
Licensed under: CC-BY-SA with attribution
Not affiliated with wordpress.stackexchange
scroll top