Support » Plugin: Meta Box - WordPress Custom Fields Framework » Problem with Metabox Tab

  • Hi,

    I have 3 tabs for 3 categories, when I want to add more than one
    Specification in these categories I have to click the button “add more”. Until this moment everything it is ok, but when I click the button “Publish” or “Update”, all the specification disappear. Only appear the last specification that I wrote. Sorry for my english, I hope you can help me.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Anh Tran

    (@rilwis)

    Hi,

    Can you post the code to register meta boxes?

    Hi, this is the code:

    <?php
    add_filter( ‘rwmb_meta_boxes’, ‘en_register_meta_boxes’ );

    function en_register_meta_boxes( $meta_boxes ) {
    /*$meta_boxes[] = array(
    ‘title’ => ‘Encabezado’,
    ‘post_types’ => array( ‘motocorp_producto’, ‘page’ ),
    ‘context’ => ‘normal’,
    ‘priority’ => ‘high’,
    // Conditional Logic can be applied to Meta Box
    // In this example: Show this Meta Box by default. Hide it when post format is aside
    ‘fields’ => array(
    array(
    ‘id’ => ‘encabezado_habilitado’,
    ‘name’ => ‘Mostrar’,
    ‘type’ => ‘checkbox’,
    ),
    array(
    ‘id’ => ‘encabezado_titulo’,
    ‘name’ => ‘Título’,
    ‘type’ => ‘text’,
    // Conditional Logic can applied to fields
    // In this example: Show this field by default,
    // hide it when user selected different value than ‘Apple’ on brand select field
    ‘visible’ => array( ‘encabezado_habilitado’, true )
    ),
    array(
    ‘id’ => ‘encabezado_fondo’,
    ‘name’ => ‘Imagen de fondo’,
    ‘type’ => ‘image_advanced’,
    ‘max_file_uploads’ => 1,
    // Conditional Logic can applied to fields
    // In this example: Show this field by default,
    // hide it when user selected different value than ‘Apple’ on brand select field
    ‘visible’ => array( ‘encabezado_habilitado’, true )
    )
    )
    );*/
    $meta_boxes[] = array(
    ‘title’ => ‘Ruta’,
    ‘post_types’ => array( ‘page’ ),
    ‘context’ => ‘normal’,
    ‘priority’ => ‘high’,
    ‘fields’ => array(
    array(
    ‘id’ => ‘ruta_habilitado’,
    ‘name’ => ‘Mostrar’,
    ‘type’ => ‘checkbox’,
    ‘std’ => ‘1’
    ),
    ),
    );
    $meta_boxes[] = array(
    ‘title’ => ‘Detalles’,
    ‘post_types’ => array( ‘motocorp_tienda’ ),
    ‘context’ => ‘normal’,
    ‘priority’ => ‘high’,
    ‘fields’ => array(
    array(
    ‘name’ => ‘Ciudad’, // Optional
    ‘id’ => ‘ciudad’,
    ‘type’ => ‘text’,
    ),
    array(
    ‘name’ => ‘Dirección’, // Optional
    ‘id’ => ‘dirección’,
    ‘type’ => ‘text’,
    ),
    array(
    ‘name’ => ‘Teléfono’, // Optional
    ‘id’ => ‘telefono’,
    ‘type’ => ‘text’,
    ),
    array(
    ‘name’ => ‘Email de contacto’, // Optional
    ‘id’ => ’email’,
    ‘type’ => ‘text’,
    ),
    array(
    ‘name’ => ‘Coordenadas en mapa’, // Optional
    ‘id’ => ‘ubicacion’,
    ‘type’ => ‘text’,
    ),
    ),
    );

    $meta_boxes[] = array(
    ‘title’ => ‘Modelo’,
    ‘post_types’ => array( ‘motocorp_producto’ ),
    ‘context’ => ‘normal’,
    ‘priority’ => ‘high’,

    ‘fields’ => array(
    array(
    ‘name’ => ‘Nombre’, // Optional
    ‘id’ => ‘modelo’,
    ‘type’ => ‘text’,
    ),
    ),
    );
    $meta_boxes[] = array(
    ‘title’ => ‘Galería de imágenes’,
    ‘post_types’ => array( ‘motocorp_producto’ ),
    ‘context’ => ‘normal’,
    ‘priority’ => ‘high’,

    ‘fields’ => array(
    array(
    ‘name’ => ‘Imágenes’, // Optional
    ‘id’ => ‘producto_galeria’,
    ‘type’ => ‘image_advanced’,
    ),
    ),
    );

    $detalles = array( ‘Motor’, ‘Chasis’, ‘Dimensiones’ );
    $tabs = array();
    $fields = array();

    foreach ( $detalles as $detalle ) {
    $key = sanitize_key( $detalle );
    $tabs[ $key ] = array( ‘label’ => $detalle );
    }
    foreach ( $detalles as $detalle ) {
    $key = sanitize_key( $detalle );
    $fields[] = array(
    ‘id’ => “producto_detalles_$key”,
    ‘type’ => ‘group’,
    ‘clone’ => true,
    ‘sort_clone’ => true,
    ‘tab’ => $key,
    ‘fields’ => array(
    array(
    ‘name’ => ‘Item’,
    ‘id’ => ‘item’,
    ‘type’ => ‘text’,
    ),
    array(
    ‘name’ => ‘Detalles’, // Optional
    ‘id’ => ‘detalle’,
    ‘type’ => ‘textarea’,
    ),
    ),
    );
    }

    $meta_boxes[] = array(
    ‘title’ => ‘Detalles del Producto’,
    ‘post_types’ => array( ‘motocorp_producto’ ),
    // List of tabs, in one of the following formats:
    // 1) key => label
    // 2) key => array( ‘label’ => Tab label, ‘icon’ => Tab icon )
    ‘tabs’ => $tabs,
    // Tab style: ‘default’, ‘box’ or ‘left’. Optional
    ‘tab_style’ => ‘left’,

    // Show meta box wrapper around tabs? true (default) or false. Optional
    ‘tab_wrapper’ => true,
    ‘fields’ => $fields
    );

    /*Metaboxes para concesionarios*/

    /*$meta_boxes[] = array(
    ‘title’ => ‘Concesionarios’,
    ‘post_types’ => array( ‘motocorp_concesionario’ ),
    ‘context’ => ‘normal’,
    ‘priority’ => ‘high’,
    ‘fields’ => array(
    array(
    ‘name’ => ‘Concesionarios’, // Optional
    ‘id’ => ‘concesionarios’,
    ‘type’ => ‘group’,
    // Clone whole group?
    ‘clone’ => true,
    // Drag and drop clones to reorder them?
    ‘sort_clone’ => true,
    // List of sub-fields
    ‘fields’ => array(
    array(
    ‘name’ => ‘Nombre’, // Optional
    ‘id’ => ‘nombre’,
    ‘type’ => ‘text’,
    ),
    array(
    ‘name’ => ‘Dirección’, // Optional
    ‘id’ => ‘direccion’,
    ‘type’ => ‘textarea’,
    ),
    array(
    ‘name’ => ‘Teléfono’, // Optional
    ‘id’ => ‘telefono’,
    ‘type’ => ‘text’,
    ),
    array(
    ‘name’ => ‘Tipo de Concesionario’, // Optional
    ‘id’ => ‘tipo_concesionario’,
    ‘type’ => ‘select’,
    ‘placeholder’ => ‘Selecciona…’,
    ‘options’ => array(
    ‘motocorp’ => ‘Motocorp Perú’,
    ‘la-curacao’ => ‘La Curacao’,
    ‘efe’ => ‘Tiendas EFE’,
    ‘otro’ => ‘Otro’
    ),
    ),
    ),
    ),
    ),
    );*/

    return $meta_boxes;
    }

    function custom_fields_marca( $tag ) {
    $t_id = $tag->term_id; // Get the ID of the term you’re editing
    $term_meta = get_option( “taxonomy_term_$t_id” ); // Do the check
    ?>

    <tr class=”form-field”>
    <th scope=”row” valign=”top”>
    <label for=”term_meta[logo_url]”>URL del logo</label>
    </th>
    <td>
    <input type=”text” name=”term_meta[logo_url]” id=”term_meta[logo_url]” size=”25″ style=”width:60%;” value=”<?php echo $term_meta[‘logo_url’] ? $term_meta[‘logo_url’] : ”; ?>”><br/>
    <span class=”description”>Url del Logo de la marca</span>
    </td>
    </tr>

    <?php
    }

    function save_custom_fields_marca( $term_id ) {
    if ( isset( $_POST[‘term_meta’] ) ) {
    $t_id = $term_id;
    $term_meta = get_option( “taxonomy_term_$t_id” );
    $cat_keys = array_keys( $_POST[‘term_meta’] );
    foreach ( $cat_keys as $key ) {
    if ( isset( $_POST[‘term_meta’][ $key ] ) ) {
    $term_meta[ $key ] = $_POST[‘term_meta’][ $key ];
    }
    }
    //save the option array
    update_option( “taxonomy_term_$t_id”, $term_meta );
    }
    }

    // Add the fields to the “presenters” taxonomy, using our callback function
    add_action( ‘marca-producto_edit_form_fields’, ‘custom_fields_marca’, 10, 2 );

    // Save the changes made on the “presenters” taxonomy, using our callback function
    add_action( ‘edited_marca-producto’, ‘save_custom_fields_marca’, 10, 2 );

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Problem with Metabox Tab’ is closed to new replies.