Support

Account

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.