This topic contains 9 replies, has 2 voices, and was last updated by  Anh Tran 5 months, 3 weeks ago.

  • Creator
    Topic
  • #11110
    Resolved
    @mindspark
    Participant

    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',
        ) );
    } );
Viewing 9 replies - 1 through 9 (of 9 total)
  • Author
    Replies
  • #11117

    Anh Tran
    Keymaster

    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
        ) );
    } );
    #11119

    @mindspark
    Participant

    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!

    #11120

    Anh Tran
    Keymaster

    Yes, it possible. You just need to select the existing venues from the dropdown.

    #11136

    @mindspark
    Participant

    Thanks for the assist!

    #11138

    @mindspark
    Participant

    it worked!

    quick follow up…

    1. im assuming I can add relationships? example – EVENTS can relate to both VENUES and TICKETS?
    2. after adding the code snippet above, a new box appears in the EVENT cpt. how can I change the box title?

    🙂

    #11148

    Anh Tran
    Keymaster

    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.

    #11153

    @mindspark
    Participant

    thanks!

    #11155

    @mindspark
    Participant

    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?

    https://snag.gy/kfyDS9.jpg
    https://snag.gy/RzjyHb.jpg

    #11209

    Anh Tran
    Keymaster

    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',
                ),
            ),
        ) );
    } );
Viewing 9 replies - 1 through 9 (of 9 total)

You must be logged in to reply to this topic.