Hi I have the below code that runs correctly in a WordPress container on my local machine but reports the following errors in the staging environment.
Can anybody explain what is happening? Even in staging the values contained in the array are actually displayed/echoed correctly.
Notice: Undefined variable: contact_repeater_array in /www/wp-content/themes/my_theme/template-parts/flexible-content/contact/contact-section.php on line 37
Notice: Undefined variable: contact_repeater_array in /www/wp-content/themes/my_theme/template-parts/flexible-content/contact/contact-section.php on line 43
<?php if ( get_row_layout() == 'contact_section' ) :
class ContactRepeaterItem {
public $icon_image;
public $title;
public $body;
}
class ContactSection {
public $contact_repeater_array;
public $map_image;
public $message;
public $ninja_forms_id;
}
$contact_section = new ContactSection();
$contact_section->map_image = get_sub_field( 'map_image' );
$contact_section->message = get_sub_field( 'message' );
$contact_section->ninja_forms_id = get_sub_field( 'ninja_forms_id' );
if ( have_rows( 'contact_repeater' ) ) :
while ( have_rows( 'contact_repeater' ) ) :
the_row();
$contact_repeater_item = new ContactRepeaterItem();
$contact_repeater_item->icon_image = get_sub_field( 'icon' );
$contact_repeater_item->title = get_sub_field( 'title' );
$contact_repeater_item->body = get_sub_field( 'body' );
// pushing the same object over and over and over to the array.
$contact_section->$contact_repeater_array[] = $contact_repeater_item;
endwhile;
endif;
function display_contact_items( $_contact_section ) {
if ( ! empty( $_contact_section->$contact_repeater_array ) ) :
foreach ( $_contact_section->$contact_repeater_array as $item ) {
?>
<div class="contact_item">
<div class="contact_icon_container">
<div class="icon">
<img src="<?php echo esc_url( $item->icon_image['url'] ); ?>" alt=""/>
</div>
</div>
<div class="contact_detail_container">
<div class="title">
<?php echo esc_html( $item->title ); ?>
</div>
<div class="body">
<?php echo esc_html( $item->body ); ?>
</div>
</div>
</div>
<?php
}
endif;
}
?>