0

I'm trying to pass ACF field value in query as value. Let me show what I have now:

array(                              
    'key' => 'office', // name of custom field
    'value' => '320', // matches exaclty "123", not just 123. This prevents a match for "1234"
    'compare' => 'LIKE'
),

As you see, I have static value now, this is an ID of post object. The problem is that this is not always "320", so I've created another relationship to choose which office you want. But now I'm confused how to pass that field value into query. I tried something like this but it return all users from all offices

$valuee = get_field( "choose_office" );
$args = array(
    'meta_query' => array(
        array(
            'key' => 'office', // name of custom field
            'value' => $valuee, // matches exaclty "123", not just 123. This prevents a match for "1234"
            'compare' => 'LIKE'
        ),
    ),  
);
0

SOLUTION:

$posts = get_field('choose_office'); if( $posts ): 
 foreach(array_slice($posts, 0, 1) as $post):
  setup_postdata($post);
  $post_ID =  get_the_ID();
   endforeach; 
   wp_reset_postdata();
   endif;

  $args = array(


'meta_query' => array(

        array(

'key' => 'office', // name of custom field-post object
'value' => $post_ID, //name of relationship field
'compare' => 'LIKE'
                            ),

                        ),  
    );

Solution from question: https://stackoverflow.com/questions/46816190/using-post-id-inside-reverse-acf-relationship-querie

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.