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.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
The most recent ACF Chat Friday featured a live demo of how to register CPTs directly in the plugin, one of our most requested features. Check out the summary below for a replay of the demo, and don’t forget to register for the next session! https://t.co/k2KQ3WWBAz
— Advanced Custom Fields (@wp_acf) March 9, 2023
© 2023 Advanced Custom Fields.
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.