I have got a custom post type (book group) set up by Metabox with a relation to another custom post type (book group location).
I have a single post template setup, which I have applied to the “book group location” post type, and I want to display details of the book group location, and a list of future book groups that are linked to that location.
I’m using a query loop to display posts that are associated with the related book group location, using the “Type = MB Relationship” (as shown below).
This works perfectly to display the correct posts. However, I would also like to apply a post order and a meta query to further refine the list of posts, but these options (shown below) are not shown when I select “Type = MB Relationship”
Is it possible to do this in Bricks using the query loop? I’ve tried using nested loops without any success so far.
Thanks but people with no coding skills must have access somehow via the builder’s UI to change these stuff. I don’t know why it’s so hard implement this. There are many posts about the same thing from many months ago.
Imagine you have a Single page template for a Book Author and want to display his books sorted by Name, Price, Year etc. Good luck doing that via code and explain that to your customer how to change it…
But relationship queries are not just simple queries, therefore the implementation is more complicated. Also, I don’t think you really want your customer to change query parameters either.
Anyway, you can of course make a first query of the post type and its posts, and within this query make a second query where you check in the meta query parameters for the post_id.
Or when you are in a single post template, you can make a query in that template with the meta query parameter for the post_id.
Both will then find all related posts that have the post_id of the post from the first query or from the single post template.
Then you have all sorting etc. query parameters.
See this for more info:
The meta key has to be the name of the relationship field and the meta value must be “{post_id}” including the quotes!
In metabox the way relationships work is that metabox creates a seperate table and stores there the related ids of the related posts. That is the best approach for scalability. It’s like you are using a foreign key table if you know how relational database tables work.
ACF on the other hand stores the relationships in postmeta table and it stores them serialized. Very bad practice but works with the querying thing of bricks.