• Hi there,

    we have a block with a repeater containing an if on a link field:

    <?php foreach( $attributes['rezension'] as $inner ){ ?>
        <?php if ( $inner['link'] ) : ?>
            Button
        <?php endif; ?>
    <?php } ?>

    When inserted on a page and the link field is initially left empty, we get a warning in the frontend:

    Warning: Undefined array key ?link“ in /htdocs/wordpress/wp-content/themes/gp-client/blocks/lazyblock-review/block.php on line 14

    After filling this field and saving and then emptying again the warning disappears.

    Any hint how to solve this?

    Regards
    Claudia

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author nK

    (@nko)

    Hey Claudia.

    Unfortunately, I can’t reproduce this error. If you can provide exported JSON code of your block, it will be helpful. https://lazyblocks.com/documentation/export-blocks/

    Regards, nK.

    Thread Starter claudiaiw

    (@claudiaiw)

    Hi,

    we changed it to isset and then it worked:

    <?php foreach( $attributes['rezension'] as $inner ){ ?>
        <?php if ( isset($inner['link']) and ($inner['link'] == true ) : ?>
            Button
        <?php endif; ?>
    <?php } ?>

    regards
    Claudia

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Repeater with if = warning “undefined array key” when initially empty’ is closed to new replies.