nito
nito

Reputation: 45

Get image alt text from cmb2 custom metabox file(CMB2)

I use wordpress cms and cmb2 plugin for registering custom metaboxes&fields. I registered image field and cant get it's alt text. How I can get image alt text in loop? I have this:

<?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 } 
                          } ?>

Will be happy for any help.. Thanks

Upvotes: 0

Views: 563

Answers (1)

Nahid Hasan
Nahid Hasan

Reputation: 471

For that, you can use another text fields for your image atl text. and show what ever you want to. if you use file_list type then all images alt text will same.

'type' => 'file_list',

Or use file type then you can get different alt text for your different image.

'type'    => 'file',

Show on fronted like as

<img alt="<?php echo get_post_meta( get_the_id(), 'your_field_id', true ); ?>" src="<?php echo $successful_students_item['successful_students_block_image']; ?>"/>

Upvotes: 1

Related Questions