• Resolved irishetcher

    (@irishetcher)


    I have been teating Pods with the Bricks builder. The one area where I need help with is with Relationships and using the built in php query editor. As such Bricks doesn’t register the relationship but, the same is true with Toolset relationships and the following will work in the php query editor:

    return [
    ‘post_type’ => ‘member’,
    ‘orderby’ => ‘desc’,
    ‘posts_per_page’ => ‘-1’,
    ‘paged’ => 1,
    ‘suppress_filters’ => true,
    ‘toolset_relationships’ => [
    ‘role’ => ‘child’,
    ‘related_to’ => get_the_ID(),
    ‘relationship’ => ‘member_of_band’,
    ]
    ];

    If I add the above for the linked band memebers on a “Band” page it returns the musicians for all the bands so in effect the code works up until it hits the nested arrray query to narrow down the ouput to the specific members of the band. Obviously I need to swap in the Pods equivalent here for toolset_relationships.

    Is there a slug for that or, an alternative to the code above? My understanding is that it must be in the array format.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Support Paul Clark

    (@pdclark)

    get_the_ID() is an ID of a currently viewed post type of type band, and member is a post type with a relationship field associated with band, there are a few ways that should work with Pods, assuming this query is following WP_Query parameters:

    Query by band ID stored in a meta field named band_relationship on members:

    return [
    'post_type' => 'member',
    'orderby' => 'desc',
    'posts_per_page' => '-1',
    'paged' => 1,
    'suppress_filters' => true,
    'meta_query' => [
    [
    'key' => 'band_relationship',
    'value' => [ get_the_ID() ],
    'compare' => 'IN',
    'type' => 'NUMERIC',
    ],
    ]
    ];

    Query by member ID stored in a bi-directional relationship field on band named members_relationship:

    return [
    'post_type' => 'member',
    'orderby' => 'desc',
    'posts_per_page' => '-1',
    'paged' => 1,
    'suppress_filters' => true,
    'post__in' => (array) get_post_meta( get_the_ID(), 'members_relationship', false ),
    ];

    Other options, but not how it seems this has been organized, would be:

    • band and members be one hierarchical post type, where wp_posts.parent = 0 means it is a band and wp_posts.members != 0 means it is a member. This is quick to query with the post_parent parameter, but does not allow for members to be a member of more than one band.
    • members to be a post type and band to be a taxonomy. This is quick to query with taxonomy parameters, but is usually avoided by developers in cases where the band template may be complex, as taxonomy templates and meta have different characteristics than post templates and meta.
    Thread Starter irishetcher

    (@irishetcher)

    Thanks Paul,

    There is a lot in there to digest. I’ll go over it and see if it will do the magic for me.

    Again, much appreciated.

    Thread Starter irishetcher

    (@irishetcher)

    Thanks again Paul. That did the trick.

Viewing 3 replies - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.