I use WordPress with CMB2 plugin to create custom meta boxes and fields.
It works perfectly but I can't get file field type image alt in the loop.
I have repeatable field type file successful_students_block_image
in meta box called successful_students_block
.
My code looks like this. It works but I don't know how to get image alt text.
<?php
$successful_students_items = get_post_meta(get_the_id() , 'successful_students_block_box', true);
if (!empty($successful_students_items))
{
foreach($successful_students_items as $successful_students_item)
{ ?>
<div class="ipd-je-8 ipd-rz-8 ipd-pv-12 ipd-ke-24">
<div class="rjeudirnskxzi nnu">
<div class="h1ge6swchqzj6de">
<div class="h1ge6swchqzj6de_cvz">
<figure class="o309iruhgtybgyu5">
<blockquote><?php echo $successful_students_item['successful_students_block_testimonial']; ?>
<div class="ingi3h38d8jj4"></div>
</blockquote>
<img alt="" src="<?php echo $successful_students_item['successful_students_block_image']; ?>"/>
<div class="ewr4i9548jfdeuthie">
<h5><?php echo $successful_students_item['successful_students_block_name_lastname']; ?>
<span>
<br/>
<?php echo $successful_students_item['successful_students_block_position']; ?>
</span>
</h5>
</div>
</figure>
</div>
</div>
</div>
</div>
<?php
}
} ?>
and this is what i have on backend in functions.php
function successful_students_blocks_register_metabox() {
$prefix = 'successful_students_block_';
$cmb = new_cmb2_box( array(
'id' => $prefix . 'metabox',
'title' => esc_html__( 'Successful Students', 'cmb2' ),
'object_types' => array( 'page', ),
'show_on' => array( 'key' => 'page-template', 'value' => 'fo4if93/tpl-successful-students.php' ),
) );
$group_field_id = $cmb->add_field( array(
'id' => $prefix . 'box',
'type' => 'group',
'repeatable' => true,
'options' => array(
'group_title' => __( 'Student {#}', 'cmb2' ),
'add_button' => __( 'Add Another Student', 'cmb2' ),
'remove_button' => __( 'Remove Student', 'cmb2' ),
'sortable' => true,
),
) );
$cmb->add_group_field( $group_field_id, array(
'name' => 'Name Lastname',
'id' => $prefix . 'name_lastname',
'type' => 'text',
) );
$cmb->add_group_field( $group_field_id, array(
'name' => 'Image',
'id' => $prefix . 'image',
'type' => 'file',
'options' => array(
'url' => false,
),
'text' => array(
'add_upload_file_text' => 'Add File'
),
) );
}
add_action( 'cmb2_init', 'successful_students_blocks_register_metabox' );
Trying to solve this problem several days. Please anybody if know will be happy for any answer^^