Support » Plugin: Advanced Custom Fields » Query custom posts filtered by ACF users id

  • I have custom post type called journals and an ACF Users field callededitors (return format User ID ).

    While adding a new journal, you can select multiple users as Editors.

    Now, I want to create a query to get all journals where the current user is assigned as editor.

    I tried something like this:

    $current_user = wp_get_current_user();
    
    $args = array(  
      'post_type' => 'journals',
      'post_status' => 'publish',
      'meta_query' => array(
         array(
           'key' => 'editors',
           'value' => $current_user->ID, 
           'compare' => 'IN'
         )
       )
    );

    How can I achieve this?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Did you figure this out? I’m having exactly the same issue. Thanks 🙂

    Thread Starter Sunday Lalbiaknia

    (@sundayamizo)

    This works for me.

    $current_user = wp_get_current_user();
    
    $args = array(  
        'post_type' => 'journals',
        'post_status' => 'publish',
        'meta_query' => array(
            array(
                'key' => 'editors',
                'value' => $current_user->ID,
                'compare' => 'LIKE'
            )
        )
    );
Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.