I have a custom post type fvc_members
Using advanced custom fields I've added a new field called user which is a relation object to an existing user.
I have the following code to query for the posts where the current user is set as user
$args = array(
'numberposts' => 5,
'post_type' => 'fvc_members',
'meta_query' => array(
array(
'key' => 'user',
'value' => '"' . get_current_user_id() . '"',
'compare' => '='
)
)
);
$posts = get_posts($args);
I've tried differnt options to write the value ( wrapped in '', wrapped in "", wihtout wrap, compare with LIKE ), however I can't find a way to get this working
get_current_user_id()
is not empty or null? Have you tried assigning it to a variable$mCurrentUserId = get_current_user_id()
before the$args
and thenvalue => $mCurrentUserID
? – Antonios Tsimourtos$args = array( 'numberposts' => 5, 'post_type' => 'fvc_members', 'meta_query' => array( array( 'meta_key' => 'user', 'meta_value' => get_current_user_id(), ) ) );
– Antonios Tsimourtoscompare
– Antonios Tsimourtos