Viewing 1 reply thread
  • Author
    Posts
    • #6040

      Q: Does post to post support hierarchical relationships?

      for example: If I create a connection type between “Continent & Country”, “Country & State”, “State & City” and then access a city post, will I have access to the data for all the parents?

    • #6054
      Jason
      Keymaster

      Hey @friendlyfire3

      I would say via configuration no, but via convention yes. 🙂

      The relationships within Piklist are really pretty informal, working by a quick and simple convention via the meta tables to determine which object has another. Rather than trying to make Piklist a configuration monster that tries to have a formal way of defining every element of a relationship (i.e. one-to-one, hierarchical, etc.) we went simple and allow developers to take it however they’d want.

      All that being said, I’ve done similar sorts of relationships and simple break my overall query into multiple queries, and since I just want the id of the relationship, I limit the query to that (via the wp_query ‘fields’ => ‘ids’ parameter).

      $state = get_posts(array(
        'suppress_filters' => false,
        'post_type' => 'state',
        'numberposts' => 1,
        'has_post' => $city->ID,
        'fields' => 'ids'
      ));
      
      $country = get_posts(array(
        'suppress_filters' => false,
        'post_type' => 'country',
        'numberposts' => 1,
        'has_post' => $state
      ));

      Hope this helps!

Viewing 1 reply thread
  • You must be logged in to reply to this topic.