• Resolved csjWP

    (@csjwp)


    I followed the instructions from github.

    If including the library in your plugin or theme:

      Place the CMB2 directory inside of your theme or plugin.
      Copy the entirety of its contents to your theme’s functions.php file.
      Edit to only include the fields you need and rename the functions (CMB2 directory should be left unedited in order to easily update the library).
      Profit.

    I’m trying to use the multiple files for images.

    $cmb_demo->add_field( array(
    		'name'         => __( 'Multiple Files', 'cmb2' ),
    		'desc'         => __( 'Upload or add multiple images/attachments.', 'cmb2' ),
    		'id'           => $prefix . 'file_list',
    		'type'         => 'file_list',
    		'preview_size' => array( 100, 100 ), // Default: array( 50, 50 )
    	) );

    I’ve set 'object_types' => array( 'mycustomposttype', ), // Post type and it works. All the fields show in admin and I add few images.

    In my content-mycustomposttype.php for displaying the metadata.

    <?php
    // Grab the metadata from the database
    $file_list = get_post_meta( get_the_ID(), '_yourprefix_file_list', true );
    
    // Echo the metadata
    echo esc_html( $file_list);
    ?>

    But when I save the post and visit the page nothing shows up.

    What am I missing?

    https://wordpress.org/plugins/cmb2/

Viewing 6 replies - 1 through 6 (of 6 total)
  • Thread Starter csjWP

    (@csjwp)

    I forgot to mention, that when I view source I just see “Array” written out.

    Thread Starter csjWP

    (@csjwp)

    Can this post be deleted? I want to start over.

    I’ve tried following this guide…
    https://github.com/WebDevStudios/CMB2/wiki/Field-Types#file_list

    Thread Starter csjWP

    (@csjwp)

    Please ignore everything else. And see this post I made on stackoverflow instead. Sorry for the mess.

    http://stackoverflow.com/questions/39165277/cmb2-multiple-files-not-displaying-on-page

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    No real way to delete the forum thread from me, and I’d prefer it not get deleted, to be honest.

    Given that you got “Array” as output, means that you’re receiving an array back from the custom field. That’s not a bad thing, it just means you aren’t going to be able to just echo out the variable once fetched, you’re going to need to iterate over it with a foreach loop, to get the actual saved values.

    Example meta value from my own dev site, for 1 file.

    array (size=1)
      10 => string 'http://wds.dev/wp-content/uploads/2016/08/734.gif' (length=49)

    In this case, the 10 is both the index value for the image in the array, as well as the attachment/post ID for the item in the media library. Useful for fetching other info, if necessary.

    To display this, I’d need to do something like the following:

    $images = get_post_meta( 2, '_my_prefix_file_list', true );
    foreach ( $images as $id => $imgurl ) {
        echo '<img src="' . $imgurl . '" alt="Media item ' . $id . '" />';
    }

    Feel free to amend as necessary for your own needs, this is just an example.

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Looks like I missed the part about the StackOverflow reply, and it looks like Justin has you covered over there.

    Good information above, regardless.

    Thread Starter csjWP

    (@csjwp)

    Yes, thank you both. I’m just trying to learn how to master this.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Display the Metadata question’ is closed to new replies.