function acf_get_field_groups($args = false) { // vars $field_groups = array(); // cache $found = false; $cache = wp_cache_get('field_groups', 'acf', false, $found); if ($found) { return acf_filter_field_groups($cache, $args); } // load from DB $posts = get_posts(array('post_type' => 'acf-field-group', 'posts_per_page' => -1, 'orderby' => 'menu_order title', 'order' => 'asc', 'suppress_filters' => false, 'post_status' => 'publish', 'update_post_meta_cache' => false)); // loop through and load field groups if ($posts) { foreach ($posts as $post) { // add to return array $field_groups[] = acf_get_field_group($post); } } // filter $field_groups = apply_filters('acf/get_field_groups', $field_groups); // set cache wp_cache_set('field_groups', $field_groups, 'acf'); // return return acf_filter_field_groups($field_groups, $args); }
function acf_get_field_groups($args = false) { // vars $field_groups = array(); $post_ids = array(); $cache_key = "get_field_groups"; // check cache for ids if (acf_isset_cache($cache_key)) { $post_ids = acf_get_cache($cache_key); // query DB for child ids } else { // query $posts = get_posts(array('post_type' => 'acf-field-group', 'posts_per_page' => -1, 'orderby' => 'menu_order title', 'order' => 'asc', 'suppress_filters' => false, 'post_status' => array('publish', 'acf-disabled'), 'update_post_meta_cache' => false)); // loop if ($posts) { foreach ($posts as $post) { $post_ids[] = $post->ID; } } // update cache acf_set_cache($cache_key, $post_ids); } // load field groups foreach ($post_ids as $post_id) { $field_groups[] = acf_get_field_group($post_id); } // filter // - allows local field groups to be appended $field_groups = apply_filters('acf/get_field_groups', $field_groups); // filter via args if ($args) { $field_groups = acf_filter_field_groups($field_groups, $args); } // return return $field_groups; }