Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expired blocks keep other blocks from displaying #403

Closed
coreymcollins opened this issue Oct 1, 2018 · 0 comments
Closed

Expired blocks keep other blocks from displaying #403

coreymcollins opened this issue Oct 1, 2018 · 0 comments

Comments

@coreymcollins
Copy link
Contributor

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;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant