• Resolved maumrs

    (@maumrs)


    Hi! I’m having problems trying to get the next code to frontend:

    function yourprefix_register_demo_metabox() {
    	//INGREDIENTES
    	$prefix = 'ingredientes_';
    	$cmb_demo = new_cmb2_box( array(
    		'id'            => $prefix . 'metabox',
    		'title'         => __( 'Receta', 'cmb2' ),
    		'object_types'  => array( 'receta', ), // Post type
    		// 'show_on_cb' => 'yourprefix_show_if_front_page', // function should return a bool value
    		// 'context'    => 'normal',
    		//'priority'   => 'high',
    		// 'show_names' => true, // Show field names on the left
    		// 'cmb_styles' => false, // false to disable the CMB stylesheet
    		// 'closed'     => true, // true to keep the metabox closed by default
    		// 'classes'    => 'extra-class', // Extra cmb2-wrap classes
    		// 'classes_cb' => 'yourprefix_add_some_classes', // Add classes through a callback.
    	) );
    
    	$cmb_demo->add_field( array(
    		'name'     => __( 'Ingredientes necesarios', 'cmb2' ),
    		'desc'     => __( 'Selecciona los ingredientes necesarios', 'cmb2' ),
    		'id'       => $prefix . 'lista',
    		'type'     => 'taxonomy_multicheck',
    		'taxonomy' => 'post_tag', // Taxonomy Slug
    		'select_all_button' => false,
    		// 'inline'  => true, // Toggles display to inline
    	) );
    
    	//PASOS
    	$grupo_pasos_id = $cmb_demo->add_field( array(
    	    'id'          => 'pasos_grupo',
    	    'type'        => 'group',
    	    'description' => __( 'Carga los pasos a seguir', 'cmb' ),
    	    'options'     => array(
    	        'group_title'   => __( 'Paso {#}', 'cmb' ), // since version 1.1.4, {#} gets replaced by row number
    	        'add_button'    => __( 'Agregar otro paso', 'cmb' ),
    	        'remove_button' => __( 'Eliminar paso', 'cmb' ),
    	        'sortable'      => true, // beta
    	    ),
    	) );
    	
    	// Id's for group's fields only need to be unique for the group. Prefix is not needed.
    	$cmb_demo->add_group_field( $grupo_pasos_id, array(
    		'name' => __( 'Describe el paso:', 'cmb2' ),
    		// 'desc' => __( 'field description (optional)', 'cmb2' ),
    		'id'   => 'descripcion',
    		'type' => 'textarea_small',
    		//'repeatable' => true,
    	) );
    
    	$cmb_demo->add_group_field( $grupo_pasos_id, array(
    		'name' => __( 'Imagen del paso:', 'cmb2' ),
    		'desc' => __( 'Sube una imagen o pega la URL.', 'cmb2' ),
    		'id'   => 'imagen',
    		'type' => 'file',
    	) );
    
    }

    And this is what I have on my single.php file:

    <code>
    				<h3>Ingredientes</h3>
    				<?php
    				
    				// This is the WordPress post ID where the data should be stored/displayed.
    				//$object_id = 0;
    				$metabox_id = 'ingredientes_lista';
    				
    				cmb2_metabox_form( $metabox_id );
    				
    				?>
    				<p></p>
    				<h3>Pasos a seguir</h3>		
    										<?php 
    						$entries = get_post_meta( get_the_ID(), 'pasos', true );
    						if ( ! empty( $entries ) ) {
    
    							foreach ( (array) $entries as $key => $entry ) {
    							
    							   $img = $desc = $caption = '';
    							
    							   if ( isset( $entry['descripcion'] ) ) {
    							    	$desc = wpautop( $entry['descripcion'] );
    								}
    							   if ( isset( $entry['imagen'] ) ) {
    							    	$img = wp_get_attachment_image( $entry['imagen'], 'share-pick', null, array( 'class' => 'thumb', ) );
    							   }
    							
    							   $caption = isset( $entry['imagen'] ) ? wpautop( $entry['imagen'] ) : '';
    							
    							   // Do something with the data
    							}
    						}
        					?>

    Can anyone tell me what am I doing wrong?
    Thanks in advance!

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    What part exactly is not working? The retrieval of the meta data?

    Regarding your get_post_meta() line, the meta key you want to use is pasos_grupo not just pasos. Very often, if not always, the ‘id’ parameters for CMB2 fields is the meta key you use, whether it be post, user, or term meta.

    Also, just in case you weren’t aware, the taxonomy_multicheck field isn’t going to save/store data like meta data, as it’s not meant to. It’s a field type meant to help replace the default WordPress metaboxes regarding categories/tags/taxonomies, and will assign terms to the post in the same way.

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Forgot to subscribe to email notifs.

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Any changes here, or did you get it figured out?

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Can’t get group of fields to frontend’ is closed to new replies.