Events to Venues
Support › MB Relationships › Events to VenuesResolved
- This topic has 9 replies, 2 voices, and was last updated 6 years, 8 months ago by
Anh Tran.
-
AuthorPosts
-
August 25, 2018 at 2:40 AM #11110
@mindspark
ParticipantHi - 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', ) ); } );
August 27, 2018 at 9:46 AM #11117Anh Tran
KeymasterHi, 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 ) ); } );
August 27, 2018 at 9:50 AM #11119@mindspark
ParticipantGot 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!
August 27, 2018 at 9:55 AM #11120Anh Tran
KeymasterYes, it possible. You just need to select the existing venues from the dropdown.
August 27, 2018 at 5:49 PM #11136@mindspark
ParticipantThanks for the assist!
August 27, 2018 at 6:37 PM #11138@mindspark
Participantit worked!
quick follow up...
- im assuming I can add relationships? example - EVENTS can relate to both VENUES and TICKETS?
-
after adding the code snippet above, a new box appears in the EVENT cpt. how can I change the box title?
🙂
August 28, 2018 at 4:49 PM #11148Anh Tran
KeymasterHi 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.
August 28, 2018 at 7:06 PM #11153@mindspark
Participantthanks!
August 28, 2018 at 8:01 PM #11155@mindspark
ParticipantAnh -
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?
September 1, 2018 at 2:23 PM #11209Anh Tran
KeymasterHi Neil,
The
title
parameter should be wrapped inside ameta_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', ), ), ) ); } );
-
AuthorPosts
- You must be logged in to reply to this topic.