Make Relationship Post Type Show In Rest

Support MB Relationships Make Relationship Post Type Show In Rest

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #35847
    Cady SmithCady Smith
    Participant

    Hello,

    Full disclosure: I don't know much about API/code, but I'm trying to muddle my way through it with the help of Integromat. I've figured out how to automate the creation of a post that is a metabox custom post type, but now I would like to take that one step further.

    I would like to automate the creation of new metabox relationships (one custom post type to another custom post type) via integromat. It doesn't appear that the relationship post type is registered as public, so integromat is unable to create one.

    The relationship is called: branch-to-employee
    It links the branch post type to the employee post type.

    I found this code to add to the child theme functions.php, but how should I modify it to make the branch-to-employee relationship post type show in rest?

    /**
    * Add REST API support to an already registered post type called 'book'.
    */
    add_filter( 'register_post_type_args', 'my_post_type_args', 10, 2 );

    function my_post_type_args( $args, $post_type ) {

    if ( 'book' === $post_type ) {
    $args['show_in_rest'] = true;

    // Optionally customize the rest_base or rest_controller_class
    $args['rest_base'] = 'books';
    $args['rest_controller_class'] = 'WP_REST_Posts_Controller';
    }

    return $args;
    }

    #35855
    Long NguyenLong Nguyen
    Moderator

    Hi,

    The relationship works like a meta box connection, it saves data in the custom table and it is not a post type so it does not work with the Rest API. You can use the field post to create the related posts, it works similarly with the relationship.
    https://docs.metabox.io/fields/post/

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.