I need to create a query by user id (user acf field)
the acf field with the user is “owner”
The query is like this:
$application = get_posts(
array(
'post_type' => 'application',
'posts_per_page' => -1,
'meta_query' => array(
array(
'key' => 'owner',
'value' => '"' . $post_id . '"',
'compare' => 'LIKE'
)
)
)
);
But this doesn’t work. How can i query by an acf user field?
Does the field allow multiple users? You only need to use the LIKE
comparison if multiple users can be selected. Otherwise the field should only hold a single user ID.
I found the solution:
i had to remove the “user_” prefix to the id as i’m using this in a user profile page:
'value' => '"' . str_replace("user_", "", $post_id ) . '"',
Well, that would also explain it. Good you found the problem.