Home Forums ACF PRO get all fields by group id


get all fields by group id

  • hi,

    im building a very complex template for products.

    it is possible to retrieve all fields for a given group id?

    and is there an easier way to retrieve all groups for a given post type?

    my current code:

    function get_acf_field_groups($post_type) {
    	$built_in = array('group_553b825363a7d', 'group_553b6f6e9891b', 'group_552fbd209f99e', 'group_552bd329a6457');
    	$output = array();
    	$args = array (
    		'post_type'			=> 'acf-field-group'
    	$groups = get_posts($args);
    	if($groups) {
    		foreach($groups as $group) {
    			if(in_array($group->post_name, $built_in))
    			$cond = unserialize($group->post_content);
    			if($cond) {
    				foreach($cond['location'][0] as $location) {
    					if('post_type' == $location['param'] && '==' == $location['operator'] && $post_type == $location['value']) {
    						$fields = get_acf_fields_by_group($group->ID); // ... searching for a function like this
          					$output[$group->ID] = $fields;
    	return $output;



  • You can get all ACF field groups by using the function acf_get_field_groups()

    You can get all of the fields in a group by using the function acf_get_fields($field_group_key)

    Getting all of the groups on a specific post type you’d need to loop through the field groups and look at the location rules.

  • I’m trying to get all fields of a specific group for a very long time now. What I need is to get all fields assigned to a specific custom post type, or if not possible, all fields inside a field group, either by the title or by the post id of the group. Or at least anyhow.

    Could anyone please provide a few bits of code for this? I am almost at wits end. Please?

    I can’t believe that there is no internal function for such a common task. Imagine to create a post from the front end, how to fill the appropriate acf fields? Or imagine a plugin setting, that defines something around this post creation, like which fields are visible? All these tasks need to know which fields are associated.

    Every helping hand is truly appreciated.I searched through the documentation and the forums for several times, and I almost googled myself to death.

  • As far as I know, no, there isn’t any function that will automatically get what you’re looking for. You might be better off posting a new topic rather than adding to another question. It will be seen by more people if it’s in a new thread with no replies.

    If you want to get all the fields assigned to a post type then you can get all the field groups with the function I posted above. Then you can loop through all the field groups and look at the location rules to see if they match the post type you’re looking for.

  • Just came across this and got all the fields for a specific field group using the below.

    if(function_exists('acf_get_field_groups')) {
                    $fieldGroup = acf_get_field_group(11);
                    $fields = acf_get_fields_by_id(11);
  • Thanks @virtuallast, that was what I was looking for.

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

The topic ‘get all fields by group id’ is closed to new replies.