Support

Account

Home Forums General Issues Get all ACF field labels associated to a specific page

Solving

Get all ACF field labels associated to a specific page

  • I am working in WordPress 4.9.5 and the following is working for me. I am hardcoding field labels into an array and then populating ACF data based on a custom page template…

    
                        $array_acf_names = [
                        'development_projects',
                        'enhancements',
                        'break_fixes',
                        'data_request',
                        'vendors'
                        ];
    
                        echo "<div class='ithub tabs'>";
                        echo "<div class='wrapper'>";
    
                        foreach($array_acf_names as $acfkey => &$acfName) {
                        $fieldObj = get_field_object($acfName);
    
                        echo "<div class='tab'>";
                        echo "<input type='radio' id='tab-{$acfkey}' name='ithub-tab-group' " .(($acfkey==0)?'checked':"") .">";
                        echo "<label for='tab-{$acfkey}'>{$fieldObj['label']}</label>";
                        echo "<div class='content'>{$fieldObj['value']}</div>";
                        echo "</div>";
                        }
                        unset($acfName);
                        echo "<hr>";            
                        echo "</div>";
                        echo "</div>";

    But I would like to advance this further. I do not want to hard-code my field labels into an array, I simply want to dynamically get all ACF fields that are associated to the given page, and then continue on with my PHP foreach loop (as shown above). Is this possible? If so, how do we get all ACF fields associated to a specific page?

    Or if easier to do, how can we get all ACF fields under any given ACF Title?

    Thanks!

  • I’m looking for the exact same answer. Did you ever find a solution?

    Thanks in advance.

  • This is currently what I am using but it is getting all fields on the page not just the group labels.

    
    $fields = get_field_objects(580);
    
    if( $fields )
    {
    	foreach( $fields as $field_name => $field )
    	{
    		echo '<div>';
    			echo '<h3>' . $field['name'] . '</h3>';
    		echo '</div>';
    	}
    }
    
Viewing 3 posts - 1 through 3 (of 3 total)

The topic ‘Get all ACF field labels associated to a specific page’ is closed to new replies.