Support Forum
Hi guys, I'm sorry to start off with such a negative post, but seriously your documentation for setting up relationships and displaying them in a view, is pretty much impossible to understand - either that or your software simply does not work.
I have wasted an entire weekend trying to setup what in Toolset is a very simple thing to do, but in Metabox is like trying to solve an impossible puzzle.
Even with your updated documentation I am no closer to being able to understand how to make things work. Please PLEASE improve your documentation for Relationships and Views - please PLEASE make some tutorial videos.
So, now on to what I am trying to achieve:
I have a custom post type called 'Sponsor' (think of Sponsor as an event, basically a sponsored event)
I then have another custom post type called 'Speaker'.
So, for each Sponsored event, I want to have one or more 'Speakers'. So in Metabox > Relationships I created a relationship called 'Sponsor Speaker' (Relationship ID 'sponsor-speaker', From Object Type 'Post', From Post Type 'Sponsor', To Object Type 'Post', To Post Type ''
I have Metabox AIO extension installed and so I am using Metabox builder and all the relevant plugins are installed and activated.
As some example code, I am loading all of my 'Sponsors' into my page, using a 'View', which has a setting type 'shortcode'. And so I am pasting in the shortcode to my Page. Here is the example code of my view:
{% set args = { post_type: 'sponsor', posts_per_page: -1 } %}
{% set posts = mb.get_posts( args ) %}
<div>
{% for post in posts %}
<div>
{{ post.title }}
{% set relationship = attribute( relationships, 'sponsor-speaker' ) %}
{% for post in relationship.to %}
{{ post.title }}
{% endfor %}
{% set relationship = attribute( relationships, 'sponsor-speaker' ) %}
{% for post in relationship.from %}
{{ post.title }}
{% endfor %}
</div>
{% endfor %}
</div>
The code for the relationship was taken from Metabox when I click 'Insert Field > Query > Then I get the option for 'sponsor-speaker' and I can select 'Connects To' or 'Connected From'. As you will see in my code I have tried clicking both of these (in case I was selecting the wrong piece), but my code above, all that I get in the front end is the post titles of my 'Sponsors', but nothing shows for the 'Speakers' (despite me having speakers connected in my Sponsor posts).
I can see from this thread = https://support.metabox.io/topic/relationship-doesnt-work-inside-a-for-loop-in-mb-view/ that I am not the only person who is having this problem. Also, please note that I have tried changing 'for post in relationship' to 'for post2 in relationship' and this does NOT work.
Please can someone urgently check if this is a bug, and if it is not a bug, then please can you tell me what is wrong with my code - please can I ask that you do not just post a link to your docs, because as I already said above, your docs are impossible for me to understand.
Thank you in advance for your help,
Keith