Skip to content

Instantly share code, notes, and snippets.

@christiaansnoei
Last active January 20, 2022 10:51
Show Gist options
  • Save christiaansnoei/b669c88290c3c43e06f57d46376a5224 to your computer and use it in GitHub Desktop.
Save christiaansnoei/b669c88290c3c43e06f57d46376a5224 to your computer and use it in GitHub Desktop.
Loop through each row of a flexible content field.
<?php
$flexible_content = '';
if( have_rows('partials', get_queried_object_id()) ):
while( have_rows('partials', get_queried_object_id()) ): the_row();
$row_layouts = [
'example-1',
'example-2',
'example-3',
];
foreach( $row_layouts as &$layout ) {
if( get_row_layout() == $layout ):
ob_start();
include( get_template_directory() . '/template-parts/partials/'.$layout.'.php' );
$flexible_content .= ob_get_clean();
endif;
}
endwhile;
endif;
echo $flexible_content;
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment