Home › Forums › General Issues › Querying a Post Object field similarly to a Relationship field › Reply To: Querying a Post Object field similarly to a Relationship field
If you’re using a post object that only allows a single value then the major difference would be in the reverse relationship query. Instead of this
'meta_query' => array(
array(
'key' => 'location', // name of custom field
'value' => '"' . get_the_ID() . '"', // matches exaclty "123", not just 123. This prevents a match for "1234"
'compare' => 'LIKE'
)
)
You would have this
'meta_query' => array(
array(
'key' => 'location', // name of custom field
'value' => get_the_ID(),
'compare' => '='
)
)
another think that you’ll need to watch out for is that if the field type was a relationship and you change it to a post object, the values stored in the fields for posts before you made the change will not be altered. You will need to manually edit each post to make the change. The query is probably working and returning the same values because none of the values have actually changed.
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!
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 Privacy Policy. If you continue to use this site, you consent to our use of cookies.