Created
January 10, 2019 02:28
-
-
Save jamesmthornton/011ff50dc7c93ec082c31662bfd0dc82 to your computer and use it in GitHub Desktop.
Get specific post from CPT relying on ACF flexible content and output to template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Open the Work CPT Loop and grab our target post Work Blocks | |
$args = get_post( 845 ); | |
$loop = new WP_Query( $args ); | |
while ( $loop->have_posts() ) : $loop->the_post(); | |
// Get Flexible Content from CPT | |
// check if the flexible content field has rows of data | |
if( have_rows('work_blocks') ): | |
// loop through the rows of data | |
while ( have_rows('work_blocks') ) : the_row(); | |
if( get_row_layout() == 'street_cred' ): | |
echo 'street_cred start =>'; | |
$street_cred_background_image = the_sub_field('street_cred_background_image'); | |
$street_cred_quote = the_sub_field('street_cred_quote'); | |
$street_cred_byline_who = the_sub_field('street_cred_byline_who'); | |
elseif( get_row_layout() == 'social_buzz' ): | |
echo 'social_buzz start =>'; | |
// $social_icon = the_sub_field('social_icon'); | |
// $social_or_video_url = the_sub_field('social_or_video_url'); | |
// $social_background_image = the_sub_field('social_background_image'); | |
endif; | |
// close the ACF flex content while loop | |
endwhile; | |
else : | |
// no layouts found | |
?>Hmm. It appears no blocks were found. You can create blocks in "Our Work" area of the Wordpress dashboard.<?php | |
endif; | |
// Close the Work CPT Loop | |
endwhile; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment