Query a post relationship in Beaver Themer
Support › MB Beaver Builder Integration › Query a post relationship in Beaver ThemerResolved
- This topic has 5 replies, 2 voices, and was last updated 4 years ago by
[email protected].
-
AuthorPosts
-
December 13, 2021 at 8:37 AM #32560
[email protected]
Participanthi there,
Is it possible to use relationship as query in metabase / Beaver Themer?
E.g. so I can show post module containing posts I have defined as related?Many thanks
PaulDecember 13, 2021 at 5:40 PM #32569[email protected]
ParticipantDecember 13, 2021 at 10:52 PM #32577Long Nguyen
ModeratorHi,
Currently, the extension MB Relationships is not working with the module Posts of the Beaver Builder. I'm going to inform the developer team to consider adding it to the to-do list for the future development of the plugin.
December 14, 2021 at 5:30 AM #32580[email protected]
ParticipantTHanks Long,
Much appreciated.
To be honest I can achieve exactly what I need in views, but I don't know how to add if statement that checks if there are any items in the loop.E.g. if there are no related posts the don't display the "Related posts" text and the ul
I know I am probably 2 lines away from this, but I can't figure it out (I tried some things but failed).
Would you mind showing me the snippet? With this it is the last thing I could not achieve with ACF / Themer Integration.{% set relationship = attribute( relationships, 'test-rel' ) %} Related posts <ul> {% for post in relationship.to %} <li><a href="{{ post.url }}">{{ post.title }}</a></li> {% endfor %} </ul>Thanks in advance!
PaulDecember 14, 2021 at 6:37 PM #32604Long Nguyen
ModeratorHi,
You can check if there is a post in the relationship to show the word "Related posts" and code block inside the condition, just like this
{% if relationship.to is not empty %} Relationship: {% for post in relationship.to %} {{ post.title }} {% endfor %} {% endif %}Refer to this documentation of Twig https://twig.symfony.com/doc/2.x/tests/empty.html
December 14, 2021 at 7:09 PM #32607[email protected]
ParticipantAbsolutely amazing. I was looking at this is not empty and it was one of the next "guesses" I was going to try - for some reason I didn't try it.
This worked absolutely perfectly and it means that metabox no having this feature in this screenshot is not a problem at all - I can just drop a shortcode into my single post templates and in fact I can totally control the markup 🙂
https://share.getcloudapp.com/mXuP0gyp - so this is no longer a problem 🙂
Thanks very much!
Cheers
Paul -
AuthorPosts
- You must be logged in to reply to this topic.