Support

Account

Home Forums General Issues Call posts based on relationship value Reply To: Call posts based on relationship value

  • As mentioned above you’ll need to do a reverse query.

    Understanding the query

    The above “get_posts” query finds all posts that are of the type “doctor”. It then finds the “location” custom field for each doctor and runs a LIKE query on the value.

    The relationship field saves it’s data as a serialized array. If you are not familiar with this format, please look up the stored value in your database. It will look something like this:

    a:2:{i:0;s:2:”35″;i:1;s:2:”33″;}
    This serialized array has 2 values, the first is “35”, the second is “33”. As this is the “location” field for a “doctor”, these 2 numbers must be the ID’s of location post types.

    In our query, the LIKE value was ‘”‘ . get_the_ID() . ‘”‘, if the location ID was 35 then the LIKE value would become ‘”35″‘. In this case, the query would match against the doctor’s location value (the serialized array shown above) and the doctor will be returned.