Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save kellenmace/c91132df024c0c468475dc456c36d5d0 to your computer and use it in GitHub Desktop.
Save kellenmace/c91132df024c0c468475dc456c36d5d0 to your computer and use it in GitHub Desktop.
Get the Slugs for All Fields in an Advanced Custom Fields Flexible Content Field
<?php
/**
* Get the slugs for all fields in an ACF Flexible Content field.
*
* @param string $flexible_content_slug The slug of the Flexible Content field.
* @param int $post_id (optional) The ID of the post. Default is current post ID.
* @return array The field slugs. Emtpy array on error or if there are no fields.
*/
function km_get_all_field_slugs_in_acf_flexible_content_field( $flexible_content_slug, $post_id = null ) {
$post_id = $post_id ?: get_the_ID();
$flexible_content_field = get_field( $flexible_content_slug, $post_id );
if ( ! is_array( $flexible_content_field ) ) {
return array();
}
return wp_list_pluck( $flexible_content_field, 'acf_fc_layout' );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment