Support Forum
Support › MB REST API › REST API Not showing all custom meta boxesResolved
Hi
I have installed the MB Rest API plugin to access the custom meta boxes nut not all are showing. Here is the API call https://support.metabox.io/topic/custom-post-type-by-two-custom-fields-via-rest-api/. It is missing two meta boxes and these are th eimportant two.
Cheers
Peter
Also doesn't work with following https://www.pdpa.co.uk/wp-json/wp/v2/events.
Hi Peter,
All fields in all meta boxes are merged and displayed in REST API responses. I see the link https://www.pdpa.co.uk/wp-json/wp/v2/events shows some fields. Can you check that fields come from all meta boxes?
In case there are some fields are missing, please check your code that registers meta boxes. Make sure there's no conditions like:
if ( is_admin() ) { // Or any similar condition
add_filter( 'rwmb_meta_boxes', 'your_meta_boxes' );
}
Hi Anh
Thanks for getting back to me apologies, the fisr URL I send was another post I was looking at, not the API call back the 2nd API call displays the same results. So yes I can see the following in the data:
meta_box {
xs_text_entry_information: "<p>TBC</p>\n"
xs_checkboxes_hotels: []
xs_text_hotels: "<p>TBC</p>\n"
xs_checkboxes_travel: []
xs_text_travel: "<p>TBC</p>\n"
xs_tv_checkbox: "0"
xs_logo_image: []
xs_website_url: ""
xs_title: ""
xs_description: ""
xs_robots: "noindex, nofollow"
}
<code></code>
But it's missing two custom meta boxes which I created in the same file as the majority of the above entries. Here is the file where I create the meta boxes, https://gist.github.com/xanthestudios/02b94880b71dd90ecbb28e5aa5ee63a2. YOu can see that most of them are shoiwng in the API results apart from xs_venue_short, xs_venue_long, xs_dates_start_date, xs_dates_end_date and xs_dates_entry_deadline.
Thank you for your input so far.
Peter
Hi Peter,
That's quite strange. I've just tried your code and all fields are showing up to me. Here is my screenshot:
https://i.imgur.com/55TiHeL.png
Can you check if those fields are not empty? Send me an email with a temporary admin account if you want me to look at the problem closer.
We have found the bug. There are meta boxes sharing the same ID, which makes them overwritten when getting values. In case anyone see the same bug, please change meta box IDs, making sure they're unique.
I am experiencing the same right now, I cannot see any metabox data coming up at all. Please help.
I have two metaboxes, and none of them shows up fine on the REST API. I don't want to use the plugin since I'd be using the API in other website, not on wordpress one. Please help.
[
{
"id": 236,
"date": "2019-10-18T08:38:14",
"date_gmt": "2019-10-18T08:38:14",
"guid": {
"rendered": "http://localhost:8888/wordpress/?post_type=trip&p=236"
},
"modified": "2019-10-24T16:15:24",
"modified_gmt": "2019-10-24T16:15:24",
"slug": "hello-trip",
"status": "publish",
"type": "trip",
"link": "http://localhost:8888/wordpress/trip/hello-trip/",
"title": {
"rendered": "Hello Trip"
},
"content": {
"rendered": "<p>This is the dummy trip content</p>\n",
"protected": false
},
"template": "",
"_links": {
"self": [
{
"href": "http://localhost:8888/wordpress/wp-json/wp/v2/trip/236"
}
],
"collection": [
{
"href": "http://localhost:8888/wordpress/wp-json/wp/v2/trip"
}
],
"about": [
{
"href": "http://localhost:8888/wordpress/wp-json/wp/v2/types/trip"
}
],
"wp:attachment": [
{
"href": "http://localhost:8888/wordpress/wp-json/wp/v2/media?parent=236"
}
],
"curies": [
{
"name": "wp",
"href": "https://api.w.org/{rel}",
"templated": true
}
]
}
}
]
You can see there are no metaboxes. Here is my code.
// For Image metabox registration
function trip_image_meta_box( $meta_boxes ) {
$prefix = 'prefix-';
$meta_boxes[] = array(
'id' => 'trip-image',
'title' => esc_html__( 'Assets', 'metabox-online-generator' ),
'context' => 'advanced',
'priority' => 'default',
'autosave' => 'false',
'post_types' => 'trip',
'fields' => array(
array(
'id' => $prefix . 'trip-link',
'type' => 'text',
'name' => esc_html__( 'Sharable Link', 'metabox-online-generator' ),
'placeholder' => esc_html__( 'Please provide link here', 'metabox-online-generator' ),
),
array(
'id' => $prefix . 'trip_image',
'type' => 'image_upload',
'name' => esc_html__( 'Image Uploads', 'metabox-online-generator' ),
'force_delete' => 'false',
'max_file_uploads' => '10',
'max_status' => true
)
)
);
return $meta_boxes;
}
add_filter( 'rwmb_meta_boxes', 'trip_image_meta_box' );
//Trip Informations metabox
function trip_information( $meta_boxes ){
$prefix = 'prefix-';
$meta_boxes[] = array(
'id' => 'trip-info',
'title' => esc_html__( 'Trip Information', 'metabox-online-generator' ),
'context' => 'advanced',
'priority' => 'default',
'autosave' => 'false',
'post_types' => 'trip',
'fields' => array(
array(
'id' => $prefix . 'trip_lang',
'type' => 'text',
'name' => esc_html__( 'Language', 'metabox-online-generator' )
),
array(
'id' => $prefix . 'trip_duration',
'type' => 'text',
'name' => esc_html__( 'Duration', 'metabox-online-generator' )
),
array(
'id' => $prefix . 'trip_costing',
'type' => 'text',
'name' => esc_html__( 'Package Price', 'metabox-online-generator' )
)
)
);
return $meta_boxes;
}
add_filter('rwmb_meta_boxes', 'trip_information');