Created
April 19, 2017 17:48
Get the Slugs for All Fields in an Advanced Custom Fields Flexible Content Field
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 | |
/** | |
* 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