Skip to content

Instantly share code, notes, and snippets.

@kodie
Last active October 19, 2022 22:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kodie/cbe1ed24e4a06d9794081628a0b1d310 to your computer and use it in GitHub Desktop.
Save kodie/cbe1ed24e4a06d9794081628a0b1d310 to your computer and use it in GitHub Desktop.
A function for WordPress that returns true or false depending on if a post's $field_name ACF field contains the $layout_name(s) flexible layout
<?php
// Returns true or false depending on if a post's $field_name ACF field contains the $layout_name(s) flexible layout
function have_flexible_layout($field_name, $layout_name, $post_id = false) {
if (function_exists('have_rows') && have_rows($field_name, $post_id)) {
while (have_rows($field_name, $post_id)) {
the_row();
if (in_array(get_row_layout(), (array) $layout_name)) {
reset_rows();
return true;
}
}
reset_rows();
}
return false;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment