Support

Account

Home Forums General Issues Reverse Relationship Meta Query Reply To: Reverse Relationship Meta Query

  • okay, how is it not working, is it returning unrelated posts or is it not returning any posts?

    This line in your code

    
    'value' => $post_id,
    

    should be

    
    'value' => '"'.$post_id.'"',
    

    the double quotes are important, see the comment in your code. ACF stores a relationship field as a serialized array of post IDs as string values. Searching for just a 1 without quotes would return 1, 12, 21, 123, 312, 321, 67549145, anything with a 1 in the post ID. Also, a serialize array stores the length of the string, so it would also return all posts with a post ID whose string length contains the post ID that you are searching for.