• Resolved Angelo Rocha

    (@angelorocha)


    How to display the information in a file list into a group of fields?

    Eg.:

    $group_field_id = $portfolioFiles->add_field(array(
    	'id' => 'portfolio_files',
    	'type' => 'group',
    	'description' => __('Files', 'omni'),
    	'options' => array(
    		'group_title' => __('File {#}', 'omni'),
    		'add_button' => __('New', 'omni'),
    		'remove_button' => __('Remove', 'omni'),
    		'sortable' => true,
    	),
    ));
    
    $portfolioAnexos->add_group_field($group_field_id, array(
    	'name' => 'Send Files',
    	'desc' => '',
    	'id' => $prefix . 'portfolio_attachment_list',
    	'type' => 'file_list',
    	'options' => array(
    		'add_upload_files_text' => 'Add',
    		'remove_image_text' => 'Remove',
    		'file_text' => 'File',
    		'file_download_text' => 'Download',
    		'remove_text' => 'Remove',
    	),
    ));

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

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

    (@tw2113)

    The BenchPresser

    For my clarity sake, is this for displaying saved data using the fields above? or are you trying to create something that helps construct the fields for when editing a post?

    Thread Starter Angelo Rocha

    (@angelorocha)

    To display the data above.

    I did so, but do not know if it’s the best way:

    foreach ((array)$attach as $key => $att) {
    	$list = '';
    	if (isset($att['portfolio_attachment_list']))
    		$list = ($att['portfolio_attachment_list']);
    
    	foreach ($list as $item){
    		echo '<li><a href="'.$item.'" title="'.How_to_get_file_title.'">'.$item.'</a></li>';
    	}
    }

    It’s correct? Or CMB2 can get this information in a different way?

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Give this a try, what you have above isn’t quite right.

    foreach ( (array) $attach as $key => $att ) {
    	if ( !empty( $att['_cmb2_portfolio_attachment_list'] ) ) {
    		foreach( $att['_cmb2_portfolio_attachment_list'] as $id => $item ) {
    			echo '<li><a href="'.$item.'" title="'. get_the_title( $id ) .'">'.get_the_title( $id ).'</a></li>';
    		}
    	}
    }
    Thread Starter Angelo Rocha

    (@angelorocha)

    Thanks Michael!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘File list into group fields’ is closed to new replies.