Support

Account

Home Forums ACF PRO Empty Array on 'acf/get_field_groups'

Solved

Empty Array on 'acf/get_field_groups'

  • Elliot,

    First of all you rock! Words aren’t enough.

    I’m working on a complex directory site that is using post objects and would like to show the object names in the columns of the admin screen for the post_type.

    I use Admin Columns Pro and they have an add-on that brings in ACF but their code is broken with ACF PRO. I’m just going over the code to save some cycles as they may not get to it and I would like to have this function working with your code and theirs (I can hack a solutions but it is not the right long-term solution).

    So They call
    apply_filters( 'acf/get_field_groups', array() ) )

    This yields an empty array.

    Do you have a new call in ACF PRO, or is there some docs somewhere as to what’s changed in PRO?

    Best,

    Steve
    DRS-NYC

  • I did some more work on this and found the following missing elements that worked in v4 and now in v5/PRO don’t work.

    apply_filters( 'acf/get_field_groups', array() )
    apply_filters( 'acf/location/match_field_groups', array(), $match_args )
    apply_filters( 'acf/field_group/get_fields', array(), $group['id'] )

    I used the following:

    acf_get_field_groups()
    acf_get_field_groups($match_args )
    acf_get_fields( $matchinggroup['ID'] )

    This ‘hack’ is working HOWEVER it is a problem because I enabled the local JSON cache directory and the fix I worked out immediately failed again.

    Your thoughts are much appreciated.

    • Elliot

    • July 22, 2014 at 2:01 pm

    Hi @drs-nyc

    Thanks for the posts, and yes, the previous filters have changed to functions (much easier to understand).

    I’m not sure what the new issue is with the JSON issue…

    Can you try adding this code before any of the above?

    
    // disable JSON to avoid conflicts between DB and JSON
    acf_disable_local();
    

    Thanks
    E

  • I will test this with the new code that was added to ‘Admin Columns Pro’ and let you know if we are still seeing the same error when the JSON is active in the local theme directory.

    Should have an answer within a day or so, if not earlier.

  • Hi Elliot & drs-nyc,

    I did try to use the acf_get_field_groups() function to check if the field group exist it did work fine and it will check if the field is existing or not, but it will cause register_field_group() function not to work or it will skip/it will not load the field group. Also I did try your suggestion to add the acf_disable_local() function still not working.

    Please see code below.

    
    class helper{
    //helper function
     public static function is_field_group_exists($value, $type='title') {
            $exists = false;
    
            if ($field_groups = acf_get_field_groups()) {
                foreach ($field_groups as $field_group) {
                    if ($field_group[$type] == $value) {
                        $exists = true;
                    }
                }
            }
            return $exists;
        }
    }
    
    //use
    if (!helper::is_field_group_exists('Field Group Title')) :
    // load acf exported php
            require_once (dirname(__FILE__) . '/includes/' . $acf_version . '/acf-field-group-exported.php');
        endif;
    
  • Hi drs-nyc and elliot upon facing this problem I did come up some solution. Some one in the forum did suggest to use post.

    Here’s the code:

    function is_field_group_exists($value, $type='post_title') {
            $exists = false;
            if ($field_groups = get_posts(array('post_type'=>'acf-field-group'))) {
                foreach ($field_groups as $field_group) {
                    if ($field_group->$type == $value) {
                        $exists = true;
                    }
                }
            }
            return $exists;
        }
Viewing 6 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.