Home Forums Add-ons Flexible Content Field Echo all flexible content field names in use on a page?


Echo all flexible content field names in use on a page?

  • Hello,

    I was wondering if you could help me figure out a function or some code that will echo out the titles of all the flexible content blocks on a page on the frontend?

    As a possible functionality recommendation or possibly plugin it would be incredible if you could filter pages / posts / cpt’s by the flex blocks in use on a page!

    We find ourselves needing this constantly. We use ACF as a page builder and right now there is no way to see what blocks are in use other than to look for them visually on the frontend or to edit the page.

  • Did you try using get_field_objects()?

    You could use a conditional to grab only Flexible Content fields:

    if ($field['type'] == 'flexible_content') { // not sure if this is correct 
    *  get all custom fields and dump for testing
    $fields = get_field_objects();
    var_dump( $fields ); 
    *  get all custom fields, loop through them and create a label => value markup
    $fields = get_field_objects();
    if( $fields )
    	foreach( $fields as $field_name => $field )
    		echo '<div>';
    			echo '<h3>' . $field['label'] . '</h3>';
    			echo $field['value'];
    		echo '</div>';

    More here:

    Does this help?

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.