0
votes

I use wordpress CMS and CMB2 METABOXES and Custom fields. Its works perfect but when I'm making loop If data in metabox not exists , this script anyway rendering empty group field. I want to give the command to script, if it is empty ----> show my custom markup code. I have this

<?php $our_advantages_items = get_post_meta( get_the_id(), 'our_advantages_block_box', true );
                                        if( !empty( $our_advantages_items ) ) {
                                        foreach( $our_advantages_items as $our_advantages_item ) { ?>
                                    <div class="cey96zggvcich3">
                                      <div class="cey96zggvcich3_cvz">
                                        <h2><?php echo $our_advantages_item['our_advantages_block_heading']; ?></h2>
                                        <div class="io2ji39349959jeij">
                                          <?php echo wpautop( $our_advantages_item['our_advantages_block_content'], 1 ); ?>
                                        </div>
                                      </div>
                                    </div>
                                    <?php }
                                    } ?>

Will be happy for any help !

1

1 Answers

0
votes

Not sure I understand what you're asking, but just add an else to your if statement

<?php if( !empty( $our_advantages_items ) ) : ?>
     //If not empty write your html here

<?php else: ?>
    //If empty write your html here
<?php endif; ?>