Home Forums General Issues Get fields of each tab


Get fields of each tab

  • Hi,

    short question: is there a posibility to get all fields of each tab with php?

    Thanks for your answer. 🙂

  • No, not directly. Tabs are basically a JavaScript construct. The field for a tab are not “IN” the tab. The tabs are inserted between fields just like other fields. JavaScript is used to hide all of the fields between one tab and the next tab when that tab is not active.

    You could us the functions acf_get_fields($group_id) to get the list of fields in the group and then loop through the fields to find a tab, then continue looping through the fields until you get the next tab, collecting a list of fields “IN” the tab along the way.

  • Thank you, John.

    Here’s my code. Maybe it’s not perfect, but it works and perhaps it will help someone else.

    <?php $tabs = acf_get_fields(27);
            for($l = 0; $l < sizeof($tabs); $l++) {
                $type = $tabs[$l]['type'];
                if($type == 'accordion') {
                    $start = $l;
                    $name = $tabs[$l]['label'];
                if(($tabs[$l+1]['type'] == 'accordion') || ($l == sizeof($tabs) - 1)) {
                    $end = $l;
                    while($start <= $end) {
                        // Here you can do with the fields whatever you want
            } ?> 

    Attention: I’m using the plugin Accordion Tab Field ( instead of the “normal” tabs. So you have to change the string ‘accordion’ to ‘tab’ for “normal” use.

  • Type tab does not exist, because tabs are not stored in DB. They show you tabs in admin with JS like @JohnHuebner said.
    You can’t list ACF types like that.

    Your code is working only with that additional plugin that you install because they probably have their own type in code structure.

  • In case it can be helpful for someone else, here’s the code to list all tabs labels from a specific fields group:

    $tabs = [];
    $feilds = acf_get_fields(INSERT_FIELDS_GROUP_ID);
    foreach ($feilds as $field) {
    	$type = $field['type'];
    	if ($type == 'tab') {
    		$tabs[] = $field['label'];
Viewing 5 posts - 1 through 5 (of 5 total)

The topic ‘Get fields of each tab’ is closed to new replies.