Custom Fields
Re-Envisioned
Support Meta Box Group Repeatable group data not in REST response

  • Creator
    Topic
  • #32701
    Resolved Glenn Ramsey
    Participant

    Hi,

    I'm trying to use meta-box to create an interface for data that will be returned by the REST API. I have the MB Rest API and Meta Box Group plugins installed.

    I have the following definition for data fields:

    add_filter( 'rwmb_meta_boxes', 'your_prefix_function_name' );
    
    function your_prefix_function_name( $meta_boxes ) {
        $prefix = '';
    
        $meta_boxes[] = [
            'title'      => __( 'Nav page', 'your-text-domain' ),
            'id'         => 'nav-page',
            'post_types' => ['page'],
            'fields'     => [
                [
                    'name'   => __( 'Group', 'your-text-domain' ),
                    'id'     => $prefix . 'group_mja12hpcr0h',
                    'type'   => 'group',
                    'clone'  => true,
                    'fields' => [
                        [
                            'name' => __( 'Name', 'your-text-domain' ),
                            'id'   => $prefix . 'name',
                            'type' => 'text',
                        ],
                        [
                            'name' => __( 'Relative url', 'your-text-domain' ),
                            'id'   => $prefix . 'url_b4fovvhcvnb',
                            'type' => 'text',
                        ],
                        [
                            'name' => __( 'Icon', 'your-text-domain' ),
                            'id'   => $prefix . 'icon_fa',
                            'type' => 'text',
                        ],
                    ],
                ],
            ],
        ];
    
        return $meta_boxes;
    }

    After adding data to a couple of these groups, in the REST response I only see this:

            "meta_box": {
                "group_mja12hpcr0h": []
            },
    

    How do I get this to work?

Viewing 6 replies - 1 through 6 (of 6 total)
  • Author
    Replies
  • #32715
    Long Nguyen
    Moderator

    Hi,

    I've tested this extension again on my local site and see it works as well, screenshots
    https://share.getcloudapp.com/RBuyK1qw
    https://share.getcloudapp.com/6quEO72z

    Can you please re-check the field group value and page ID?

    http://yoursite.com/wp-json/wp/v2/pages/1234

    #32727
    Glenn Ramsey
    Participant

    Thanks Long,
    I missed out an important parameter, sorry. I'm wanting to do this with a Private page that can only be accessed by an authenticated user.
    It works on a Public page for me also, as you have pointed out.

    #32730
    Long Nguyen
    Moderator
    #32732
    Glenn Ramsey
    Participant

    The issue not how to access private posts. The issue is that the empty group_* result I posted initially only occurs if I set the page to private and access it as described in that stackoverflow answer.

    This an example command I use for testing where it fails as described above.
    curl -k --user user:passwd "https://myapp.local/wp-json/wp/v2/pages?_embed"

    As already mentioned if the page is set to public then it works as expected.

    #32734
    Glenn Ramsey
    Participant

    Sorry, I copied the wrong thing, in the above post, the example command is actually this
    curl -k --user user:passwd "https://myapp.local/wp-json/wp/v2/pages?_embed&status=private"

    #32756
    Glenn Ramsey
    Participant

    Solved. It started working after I restarted the server.

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