How to store and retrieve custom metabox data as json in wordpress api

I am trying to store metabox data as json in wordpress and then get it using wp-json api.

What i tried

$  current = array(   'id' => "in json object",   'name' => 'name in json object' ); $  serializedArray = unserialize($  current); update_post_meta($  post_id, 'ha_basic_information', serialize($  current)); 

What i am trying to achieve {"id": "in json object", "name": "name in json object"}

What i am getting "s:75:\"a:2:{s:2:\"id\";s:14:\"in json object\";s:4:\"name\";s:19:\"name in json object\";}\";"

I want to get data as object in wp-json api. I’ve tried serialize/unserialize, json_encode/json_decode but nothing seems to work. I am new in php and can’t figure it out. there are many questions related to this but nothing seems to work.

Add metabox plugin data but as custom fields or php code instead

i am using a theme that has custom post type and this custom post type has two ‘boxes’ or fields or whatever they are named i will include the meta codde below now the problem is i am using a plugin to add the posts but the plugin can only add via regular custom fields with value , and i can get the value but i don’t know how to format them in such a way the metabox adds them to the database the is is how they show in the database enter image description here

here is the full code for each one of them this one is for ab_embedgroup

a:2:{i:0;a:3:{s:11:"ab_hostname";s:2:"sd";s:8:"ab_embed";s:203:"<iframe width="1263" height="480" src="https://www.youtube.com/embed/5Gsdtetr1zo" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>";s:6:"_state";s:8:"expanded";}i:1;a:3:{s:11:"ab_hostname";s:7:"fsdqfsd";s:8:"ab_embed";s:203:"<iframe width="1263" height="480" src="https://www.youtube.com/embed/5Gsdtetr1zo" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>";s:6:"_state";s:8:"expanded";}} 

and this one is for ab_downloadgroup which keep in mind i added nothing there meaning this is the default value

a:1:{i:0;a:1:{s:6:"_state";s:8:"expanded";}} 

now here is the meta file which is code for metabox settings and format

$  meta_boxes[] = array(         'id'         => 'episode',         'title'      => __( 'Episode' ),         'post_types' => array( 'watch' ),         'context'    => 'normal',         'autosave'   => true,         'fields'     => array(             array(                 'name'  => __( 'Episode' ),                 'id'    => "{$  prefix}eps",                 'type'  => 'text',             ),             array(                 'name'  => __( 'Episode Title' ),                 'id'    => "{$  prefix}epstitle",                 'type'  => 'text',             ),             array(                 'name' => __('Status', 'meta-box'),                 'id' => "{$  prefix}lang",                 'type' => 'radio',                 'options' => array(                     'RAW' => __('RAW', 'meta-box'),                     'Sub' => __('Sub', 'meta-box'),                 ),                 'multiple' => false,                 'std' => 'Sub'             ),             array(                 'name' => __('Series', 'meta-box'),                 'id' => "{$  prefix}series",                 'type' => 'post',                 'post_type' => 'series',                 'field_type' => 'select_advanced',                 'query_args' => array(                     'post_status' => 'publish',                     'posts_per_page' => -1,                     'orderby' => 'title',                     'order' => 'ASC'                 )             ),         ),     );     $  meta_boxes[] = array(         'title'  => 'Embed Video',         'pages' => array( 'post','watch' ),         'tabs'      => array(             'input-version' => array(                 'label' => 'Input Version',                 'icon'  => 'dashicons-admin-customizer',             ),             'sc-version'  => array(                 'label' => 'Shortcode Version',                 'icon'  => 'dashicons-editor-code',             ),         ),         'tab_style' => 'default',         'fields' => array(             array(                 'id'     => 'ab_embedgroup',                 'type'   => 'group',                 'clone'  => true,                 'sort_clone'  => true,                 'save_state' => true,                 'desc' => '<b style="color:red;">You can insert embed code or shortcode</b>',                 'tab'  => 'input-version',                 'fields' => array(                     array(                         'name'  => 'Host Name',                         'id'    => 'ab_hostname',                         'type'  => 'text',                     ),                     array(                         'name'   => 'Embed',                         'id'     => 'ab_embed',                         'type'   => 'textarea',                         'sanitize_callback' => 'none',                     ),                 ), //episode             ), //input-version             array(                 'name'  => __( 'Shortcode Video', 'meta-box' ),                 'id'    => "{$  prefix}embed",                 'type'  => 'textarea',                 'clone' => 'true',                 'sort_clone'  => true,                 'sanitize_callback' => 'none',                 'tab' => 'sc-version',             ),         ),     );     $  meta_boxes[] = array(         'title'  => 'Download',         'pages' => array( 'post','watch' ),         'tabs'      => array(             'input-version' => array(                 'label' => 'Input Version',                 'icon'  => 'dashicons-admin-customizer',             ),             'sc-version'  => array(                 'label' => 'Shortcode Version',                 'icon'  => 'dashicons-editor-code',             ),         ),         'tab_style' => 'default',         'fields' => array(             array(                 'id'     => 'ab_downloadgroup',                 'type'   => 'group',                 'clone'  => true,                 'sort_clone'  => true,                 'tab'  => 'input-version',                 'save_state' => true,                 'fields' => array(                     array(                         'name'  => 'Host Name',                         'id'    => 'ab_hostname',                         'type'  => 'text',                         'columns' => '3',                     ),                     array(                         'name'   => 'Language',                         'id'     => 'ab_language',                         'type'   => 'text',                         'columns' => '3',                     ),                     array(                         'name'   => 'Quality',                         'id'     => 'ab_quality',                         'type'   => 'text',                         'columns' => '3',                     ),                     array(                         'name'   => 'Link',                         'id'     => 'ab_linkurl',                         'type'   => 'text',                         'columns' => '3',                         'sanitize_callback' => 'none',                     ),                 ),             ), //input-version             array(                 'name'  => __( 'Shortcode Download', 'meta-box' ),                 'id'    => "{$  prefix}url",                 'type'  => 'textarea',                 'desc'  => 'Example: [dl n="FileHosting" u="http://domain.xxx" s="English" q="HD"]',                 'clone' => 'true',                 'sanitize_callback' => 'none',                 'tab' => 'sc-version',             ),         ),     ); 

here is how they show on the dashboard this the first box enter image description here

here is the second box enter image description here

and thank you in advace 🙂

Warning: Invalid argument supplied for foreach() Metabox WordPress

Estou utilizado o plugin Metabox para o WordPress só que não estou conseguindo trazer o array com os valores setados acontece o erro Warning: Invalid argument supplied for foreach() só que não consegui encontrar o erro, alguém poderia me ajudar? já tentei retornar os valores com o id da função fieldset e fieldset_text_id, porém não dá certo.

Meu código Metabox

function looping_fieldset_text_demo( $  meta_boxes ) {     $  meta_boxes[] = array(         'id' => 'fieldset',     'title'  => __( 'Informações do produto', 'looping' ),     'post_types' => array( 'products', 'post' ),         'fields' => array(             array(                 'id'      => 'fieldset_text_id',                 'name'    => __( 'Adicionar informações', 'looping' ),         'type'    => 'fieldset_text',         'add_button' => __('Adicionar', 'looping'),                 // Options: array of Label => key for text boxes                 // Note: key is used as key of array of values stored in the database                 // Number of options are not limited                 'options' => array(                     'ref'    => __( 'REF:', 'looping' ),                     'cod' => __( 'COD', 'looping' ),                     'mt-ncm'   => __( 'MT-NCM', 'looping' ),                 ),                 'clone' => true,             ),         ),     );     return $  meta_boxes; } add_filter( 'rwmb_meta_boxes', 'looping_fieldset_text_demo' ); 

no meu Index – Adicionei um var_dump(), para ver o resultado e ele retorna NULL

 <div class="products-list">         <h1><img src="<?php bloginfo('template_directory'); ?>/img/products-img-text.png"></h1>       <?php          $  args = array(           'post_type' => 'products',            'post_per_page' => 7,         );         $  query = new WP_Query($  args);         if($  query->have_posts()) : while($  query->have_posts()) : $  query->the_post();       ?> <div class="product-ref">       <div class="ref">         <?php            $  values = rwmb_meta( $  fieldset );           foreach ( $  values as $  value ) {               echo $  value['ref'];               echo $  value['cod'];               echo $  value['ncm'];           }           var_dump($  fieldset);         ?>       </div><!-- .ref -->     </div><!-- .product-ref -->  <?php       ?>       <?php endwhile; endif;       wp_reset_postdata(); ?> 

Adicionando valores a metabox, usando o xmlrpc + wordpress

Tenho o seguinte script, ele cria posts em um determinado wordpress.

import datetime, xmlrpclib  wp_url = "http://127.0.0.1:8080/wp/xmlrpc.php" wp_username = "admin" wp_password = "admin" wp_blogid = "" status_draft = 0 status_published = 1  server = xmlrpclib.ServerProxy(wp_url)  title = "Title with spaces" content = "Body with lots of content" date_created = xmlrpclib.DateTime(datetime.datetime.strptime("2011-10-20 21:08", "%Y-%m-%d %H:%M")) categories = ["category here"] tags = ["sometag", "othertag"]  data = {'title': title, 'description': content, 'dateCreated': date_created, 'categories': categories, 'mt_keywords': tags}  post_id = server.metaWeblog.newPost(wp_blogid, wp_username, wp_password, data, status_published) 

Ele funciona perfeitamente, mas… Preciso adicionar também valores aos atributos extras do metabox, do post wordpress.

Exemplo de metabox: inserir a descrição da imagem aqui

Script metabox:

add_filter( 'rwmb_meta_boxes', 'prefix_meta_boxes' ); function prefix_meta_boxes( $  meta_boxes ) {     $  meta_boxes[] = array(         'title'  => 'Test Meta Box',         'fields' => array(             array(                 'id'   => 'name',                 'name' => 'Name',                 'type' => 'text',             ),             array(                 'id'      => 'gender',                 'name'    => 'Gender',                 'type'    => 'radio',                 'options' => array(                     'm' => 'Male',                     'f' => 'Female',                 ),             ),             array(                 'id'   => 'email',                 'name' => 'Email',                 'type' => 'email',             ),             array(                 'id'   => 'bio',                 'name' => 'Biography',                 'type' => 'textarea',             ),         ),     );     return $  meta_boxes; } 

Como faço para adicionar valores a essas informações do metabox?

How to prevent other metaboxes from moving when inserting your own custom metabox?

This code below is making other fields all move to the side. I was only trying to make the new custom metabox move to the side.

function vmo_code_enable_metabox() {   $  screens = ['post', 'page'];   foreach ($  screens as $  screen) {     add_meta_box(       'vmo_override_options',           // Unique ID       'Individual override A/B testing code',  // Box title       'vmo_code_enable_html',  // Content callback, must be of type callable       $  screen,                  // Posts & Pages       'side',       'high'     );   } } add_action('add_meta_boxes', 'vmo_code_enable_metabox'); 

enter image description here

Shortcode of Custom Post Type Metabox Array

I have an Custom Post Type which dynamically creates 2 textboxes, one for date and one for description. In my single-template I use the following code, which functions perfect. But when I use it in a shortcode function nothing happens.

    <table class="programm">      <?php $  args = array( 'post_type' => 'programm', 'orderby' => 'date', 'order' => 'ASC' );         $  loop = new WP_Query( $  args );         while ( $  loop->have_posts() ) : $  loop->the_post();          $  programmDetails = get_post_meta($  post->ID,'programmDetails',true);         ?>               <?php foreach((array)$  programmDetails as $  pD ){                 if (isset($  pD['date']) || isset($  pD['desc']) ): ?>                     <tr>                         <td><?php echo $  pD['date'] ?></td>                         <td><?php echo $  pD['desc'] ?></td>                     </tr>                 <?php endif; } ?>         <?php endwhile; ?>     </table>