Support

Account

Home Forums Add-ons Repeater Field Sort Employees based on a acf field in tabs

Solving

Sort Employees based on a acf field in tabs

  • Hello everyone.

    I am working on tabs right now to display employees based on their department.
    Employees is a repeater field where they have set upp all their employees with name, department, email, image, phone etc.

    I have created the tabs from “department” so that the Tab names are correct:

    <?php 
    
        $i = 1;
    						
        if( have_rows('employee') ) :
    
            $select = get_sub_field_object('department');
            $value = get_sub_field('department');
            $department = $select['choices'];
    
            $isFirst = true;
    
            foreach($department as $key => $value) :
    ?>
    
        <li class="tabs-title <?php echo $isFirst ? 'is-active' : ''; ?> "><a href="#panel<?php echo $i; ?>" aria-selected="true"><?php echo $value; ?></a></li>
    					
    <?php $isFirst = false; $i++; endforeach; endif; ?>

    These tabs are now created.
    Now I need to make the content. But the employees needs to be sorted in their “content” based on the contents name (Tab names that is department name).

    Is there any way to do this without doing multiple calls in each Tab? Now there are 3 tabs, but there might be a total of 10-16 eventually.

    Have a good day, thanks.

  • It is going to be very complicated doing this using a repeater field. You will need to re-sort the rows of the repeater multiple times. Here is a guide on sorting repeater fields https://www.advancedcustomfields.com/resources/how-to-sorting-a-repeater-field/

    This would be better accomplished using a custom post type for employees and a custom taxonomies for sorting.

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

You must be logged in to reply to this topic.