User to Post Relationship - Remove Metabox From User Profile

Support MB Relationships User to Post Relationship - Remove Metabox From User ProfileResolved

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #22572
    JCJC
    Participant

    I am using the MB-Relationships plugin and the MB-User-Meta plugin together and things are working great! Thanks.

    However, I am making relationships between users and posts programatically and I don't want the connected posts to appear in the user profile. I am able to hide post metaboxes really easily by using the standard WordPress remove_meta_box() function but I'm unsure how to remove the relationship fields from the User profile. Please can you advise?

    Thank you and all the best 🙂

    #22577
    Long NguyenLong Nguyen
    Moderator

    Hi JC,

    We can use the argument 'reciprocal' => true to only show the relationship meta box when editing the post, only show for the from argument.

    add_action( 'mb_relationships_init', function() {
        MB_Relationships_API::register( [
            'id'   => 'posts_to_users',
            'from' => array(
              'object_type'  => 'post',
              'post_type'    => 'post',
            ),
            'to' => array(
              'object_type'  => 'user',
            ),
            'reciprocal' => true
        ] );
    } );

    https://docs.metabox.io/extensions/mb-relationships/#reciprocal-relationships

    #22580
    JCJC
    Participant

    Thank you, that makes a lot of sense. I missed this in the docs.

    When setting up the relationship, I went from users to posts, not from posts to users. Thankfully I haven't deployed the website yet so I can change this and make reciprocal = true.

    Out of curiosity, is there a way to remove the metabox from the "from" side? Or must it always be the metabox on the "to" side that is removed?

    Thanks again.

    #22583
    Long NguyenLong Nguyen
    Moderator

    Hi,

    By default, the meta box only shows for from object. You can switch object from and to to remove the meta box in the post and show in the user profile.

    MB_Relationships_API::register( [
            'id'   => 'posts_to_users',
            'from' => array(
              'object_type'  => 'user',
            ),
            'to' => array(
              'object_type'  => 'post',
              'post_type'    => 'post',
            ),
            'reciprocal' => true
        ] );
Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.