Snippets

nvisionsolution Flexible Layouts Loop - Call To Action

Created by Mark Grabowiecki
<?php

if ( get_sub_field( 'cta' ) ) :

    $args = array(
        'post_type' => 'ctas',
        'p' => get_sub_field( 'cta' ),
    );

    $cta = new WP_Query( $args );

    if ( $cta->have_posts() ) :
    
        while ( $cta->have_posts() ) :
            $cta->the_post();

            // check if the flexible layouts field has rows of data
            if ( have_rows( 'flexible_layouts' ) ) :
            
                // loop through the rows of layouts
                while ( have_rows( 'flexible_layouts' ) ) : the_row();
                    get_template_part( 'partials/flexible-layouts/' . get_row_layout() );
                endwhile;
                
            else :
                // no layouts found
            endif;

        endwhile;
        
        wp_reset_postdata(); // IMPORTANT
        
    endif;

endif;

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.