Support

Account

Home Forums Front-end Issues If repeater field in functions.php Reply To: If repeater field in functions.php

  • You’ll want to use the acf/input/admin_footer action to run jQuery for this. Also, I would create the tab that you want in the field group.

    Basically, you could look to see if there are rows in the body of that repeater field table then hide the tab if there are no rows . This script will get triggered when the edit post page is ready.

    It would look something like this:

    
    function check_for_videos() {
    
    ?>
    <script>
    var rowCount = jQuery('#acf-group_571814caa0f78 table tbody).find('tr');
    	if(rowCount.length == 0 ){
    		
    		jQuery('tab field selector here').hide();
    		
    }
    </script>
    <?
    }
    
    add_action('acf/input/admin_footer', 'check_for_videos');
    
    

    The most challenging part for me when doing this is getting the selector field correct to run the jQuery. If you’re not familiar with jQuery, you have to refer to the element that you want to run the script on and sometimes it’s hard to nail that down.