You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When one block has an expiration date, it stops the other blocks on the page from displaying. I believe this is due to the way the conditional returns, which means only the first set of values for dates is being used forever:
if ( have_rows( 'content_blocks' ) ) :
while ( have_rows( 'content_blocks' ) ) :
the_row();
// Get block other options.
$other_options = get_sub_field( 'other_options' ) ? get_sub_field( 'other_options' ) : get_field( 'other_options' )['other_options'];
// If the block has expired,then bail!
if ( _s_has_block_expired( array(
'start_date' => $other_options['start_date'],
'end_date' => $other_options['end_date'],
) ) ) {
return false;
}
get_template_part( 'template-parts/content-blocks/block', get_row_layout() ); // Template part name MUST match layout ID.
endwhile;
wp_reset_postdata();
endif;
Since we return after the first block is made to stop, we never get to wp_reset_postdata() so the values never get dumped for the next block.
I think the way around this is to replace return false; with a continue, which will stop the expired block from displaying but allow the loop to finish and run wp_reset_postdata() for the next block:
if ( have_rows( 'content_blocks' ) ) :
while ( have_rows( 'content_blocks' ) ) :
the_row();
// Get block other options.
$other_options = get_sub_field( 'other_options' ) ? get_sub_field( 'other_options' ) : get_field( 'other_options' )['other_options'];
// If the block has expired,then bail!
if ( _s_has_block_expired( array(
'start_date' => $other_options['start_date'],
'end_date' => $other_options['end_date'],
) ) ) {
continue;
}
get_template_part( 'template-parts/content-blocks/block', get_row_layout() ); // Template part name MUST match layout ID.
endwhile;
wp_reset_postdata();
endif;
The text was updated successfully, but these errors were encountered:
When one block has an expiration date, it stops the other blocks on the page from displaying. I believe this is due to the way the conditional returns, which means only the first set of values for dates is being used forever:
Since we return after the first block is made to stop, we never get to
wp_reset_postdata()
so the values never get dumped for the next block.I think the way around this is to replace
return false;
with acontinue
, which will stop the expired block from displaying but allow the loop to finish and runwp_reset_postdata()
for the next block:The text was updated successfully, but these errors were encountered: