Support

Account

Home Forums ACF PRO Meta Query based on User field with multiple value

Helping

Meta Query based on User field with multiple value

  • Hey guys.
    So, I have 3 fields attached to a post – Edited By, Revised By and Written by.
    The field types are „user field” with multiple values selectable.
    They are set to output an object.

    I want to query posts in an author archive page and get only the posts that have that author attached to them in one of the 3 fields.

    And here we get to the meta query:

    					'meta_query'	=> array(
    						'relation' => 'OR',
    						array(
    							'key'	 	=> 'post_revised',
    							'value'	  	=> '',
    							'compare' 	=> 'IN',
    						),
    						array(
    							'key'	 	=> 'post_edited',
    							'value'	  	=> '',
    							'compare' 	=> 'IN',
    						),
    						array(
    							'key'	 	=> 'post_written',
    							'value'	  	=> '',
    							'compare' 	=> 'IN',
    						),
    					),

    Which is the value I should check for? User ID, object?

    Thanks in advance!

  • Users are stored by ID and you need to use “LIKE” with quotes around the ID.

    an example:

    
    array(
      'key' => 'post_revised',
      'value' => '"'.$user_id.'"',
      'compare' => 'LIKE',
    ),
    
Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.