how to use image / file upload of metabox wordpress plugin?

1

I'm new creating wordpress themes, but I was recommended to use MetaBox a wordpress plugin to create Custom Goals almost easily, well the problem arises when I want to show the images that I put in my post using the new goal generated by this plugin ; When I want to do the call inside a loop, it does not stop the content, I only get "ARRAY", but with the fields I use the same goal if you show them to me.

<?php

add_filter( 'rwmb_meta_boxes', 'mc_register_meta_boxes' );

function mc_register_meta_boxes( $meta_boxes ) {
    $prefix = 'mc_';
    $meta_boxes[] = array(
        'id'         => 'standard',
        'title'      => esc_html__( 'Standard Fields', 'mc' ),
        'post_types' => array( 'post', 'page' ),
        'context'    => 'normal',
        'priority'   => 'high',
        'autosave'   => true,
        'fields'     => array(

            // IMAGE ADVANCED
            array(
                'name'             => esc_html__( 'Image Advanced Upload', 'mc' ),
                'id'               => "{$prefix}imgadv",
                'type'             => 'image_advanced',
                'max_file_uploads' => 4,
            ),
        ),
    );

    return $meta_boxes;
}

This way I place them inside a loop.

<?php echo rwmb_meta('mc_imgadv'); ?>

the result is always the word ARRAY, and it does not show me the image (s) loaded.

    
asked by MichaelCardoza 07.01.2017 в 01:13
source

1 answer

1

Dear the correct code so that it works for you is the following, I made it run on a slider without problems.

What I added was the call by variable $images to the metabox, then having said variable I did a foreach since being multiple files it is possible that it has more than one. Therefore, I traced the variable and I was printing it within the ul to be ready to be used in a slider for example.

Of course, in a JavaScript code, the flexslider configuration must be added, but the code also serves for a common gallery without a slider.

functions.php

add_filter( 'rwmb_meta_boxes', 'mc_register_meta_boxes' );

function mc_register_meta_boxes( $meta_boxes ) {
    $prefix = 'mc_';
    $meta_boxes[] = array(
        'id'         => 'standard',
        'title'      => esc_html__( 'Standard Fields', 'mc' ),
        'post_types' => 'tu-post-type',
        'context'    => 'normal',
        'priority'   => 'high',
        'autosave'   => true,
        'fields'     => array(

            // IMAGE ADVANCED
            array(
                'name'             => esc_html__( 'Image Advanced Upload', 'mc' ),
                'id'               => "{$prefix}imgadv",
                'type'             => 'image_advanced',
                'max_file_uploads' => 4,
            ),
        ),
    );

    return $meta_boxes;
}

And then in your page template:

        <?php

          /*
          *  The following code creates the thumbnail navigation
          *  Flexslider
          */ 
          $images =  rwmb_meta('mc_imgadv');

          ?>  

          <span class="bars-title">
          <div id="carousel" class="flexslider" style="width: 100%;">
            <ul class="slides">
              <?php foreach( $images as $property_image ): ?>
                <li>
                  <img src="<?php echo $property_image['url']; ?>" alt="<?php echo $property_image['alt']; ?>" />
                </li>
              <?php endforeach; ?>
            </ul>
          </div>
          </span>

I hope it works for you! It works perfect to have multiple images!

    
answered by 13.03.2017 в 19:08