Repeatable group data not in REST response
- This topic has 6 replies, 2 voices, and was last updated 3 years, 4 months ago by
Glenn Ramsey.
-
AuthorPosts
-
December 17, 2021 at 10:58 AM #32701
Glenn Ramsey
ParticipantHi,
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 MB 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?
December 17, 2021 at 6:30 PM #32715Long Nguyen
ModeratorHi,
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/6quEO72zCan you please re-check the field group value and page ID?
http://yoursite.com/wp-json/wp/v2/pages/1234
December 18, 2021 at 3:14 AM #32727Glenn Ramsey
ParticipantThanks 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.December 18, 2021 at 9:06 AM #32730Long Nguyen
ModeratorHi,
You can follow this topic to access private posts via WP REST API https://stackoverflow.com/questions/30541838/how-to-retrieve-private-posts-from-wordpress-using-json-rest-api
December 18, 2021 at 10:42 AM #32732Glenn Ramsey
ParticipantThe 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.
December 18, 2021 at 5:19 PM #32734Glenn Ramsey
ParticipantSorry, 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"
December 20, 2021 at 8:19 AM #32756Glenn Ramsey
ParticipantSolved. It started working after I restarted the server.
-
AuthorPosts
- You must be logged in to reply to this topic.