Support Forum
Support › MB Relationships › Events to VenuesResolved
Hi - I am using MB to create Events CPT. For each event I have created custom fields for the event info. But, I want to create a separate CPT for Venues. That way I can just assign a venue to an event vs retyping venue info over and over again.
So this seems like a post to post relationship... right?
I need a little help using the examples provided to set this up correctly. Will this work?
add_action( 'mb_relationships_init', function() {
MB_Relationships_API::register( array(
'id' => 'posts_to_posts',
'from' => 'post',
'to' => 'post',
) );
} );
Hi, it should be like this:
add_action( 'mb_relationships_init', function() {
MB_Relationships_API::register( array(
'id' => 'posts_to_posts',
'from' => 'event', // Your event CPT
'to' => 'venue', // Your venue CPT
) );
} );
Got it thx!
Once I add this code, will I be able to add the related cpts?
I mean when creating a new event, will I be able to add an existing venue and if so where will I be able to do that? Via a field drop down,etc?
Thx!
Yes, it possible. You just need to select the existing venues from the dropdown.
Thanks for the assist!
it worked!
quick follow up...
after adding the code snippet above, a new box appears in the EVENT cpt. how can I change the box title?
🙂
Hi Neil,
1 - Yes, you can add more relationships. Just repeat the code MB_Relationships_API::register
.
2 - To change the box title, please set the relationship info when you register it.
I've written in details about that in the documentation. Please take a look.
thanks!
Anh -
think I've missed something....
This is my code:
add_action( 'mb_relationships_init', function() {
MB_Relationships_API::register( array(
'id' => 'posts_to_pages',
'from' => 'session-sponsor',
'to' => 'session',
) );
MB_Relationships_API::register( array(
'from' => 'speaker',
'to' => 'session',
) );
} );
and
add_action( 'mb_relationships_init', function() {
MB_Relationships_API::register( array(
'id' => 'posts_to_pages',
'from' => array(
'object_type' => 'post',
'post_type' => 'session-sponsor',
'admin_column' => 'true', // THIS!
'title' => 'Sponsor',
),
'to' => array(
'object_type' => 'post',
'post_type' => 'session',
'admin_column' => 'after title', // THIS!
'title' => 'Sponsor',
),
) );
MB_Relationships_API::register( array(
'from' => array(
'object_type' => 'post',
'post_type' => 'speaker',
'admin_column' => 'true', // THIS!
'title' => 'Sponsor',
),
'to' => array(
'object_type' => 'post',
'post_type' => 'session',
'admin_column' => 'after title', // THIS!
'title' => 'Speaker',
),
) );
} );
So inside the CPT area - the boxes remain titled 'Connects To' and 'Connects From'. Also, in the all posts page - the title isn't changed there either.
I think I may not understand what I need to do here. My goal is to change the 'Connects From' title to 'Speakers' and the 'Connects To' title to 'Sponsors'. Is this possible?
Hi Neil,
The title
parameter should be wrapped inside a meta_box
parameter, like this:
add_action( 'mb_relationships_init', function() {
MB_Relationships_API::register( array(
'id' => 'posts_to_pages',
'from' => array(
'object_type' => 'post',
'post_type' => 'session-sponsor',
'admin_column' => true,
'meta_box' => array(
'title' => 'Sponsor',
),
),
'to' => array(
'object_type' => 'post',
'post_type' => 'session',
'admin_column' => 'after title',
'meta_box' => array(
'title' => 'Sponsor',
),
),
) );
MB_Relationships_API::register( array(
'from' => array(
'object_type' => 'post',
'post_type' => 'speaker',
'admin_column' => true,
'meta_box' => array(
'title' => 'Sponsor',
),
),
'to' => array(
'object_type' => 'post',
'post_type' => 'session',
'admin_column' => 'after title',
'meta_box' => array(
'title' => 'Speaker',
),
),
) );
} );