Support

Account

Home Forums ACF PRO Get field values by group

Solving

Get field values by group

  • Sorry if I’m missing this but is there a function to get the field value for a post by group?

  • Hi @zestsms

    Yes, ACF PRO contains functions within the api-field.php and api-field-group.php files to load field groups and their fields, from there, you can load the value using the api-value.php acf_get_value( $post_id, $field ) function.

    Are the fields within the DB, JSON or PHP?

  • So basically I would loop through acf_get_field_groups() to get the field keys, then loop through acf_get_fields() with the keys to get the field IDs, then loop through acf_get_value() with the field ID and post ID.

    I am creating an array with posts from a post type and their post meta and setting it as a transient (is this unnecessary?). I am currently using get_fields which works well but I wish I could separate the fields by group inside of the array easily so if there are any fields added I won’t have to go in and update the PHP.

  • Hi @zestsms

    Yes, your logic sounds correct.
    Is the transient unnecessary? I’m not sure I can provide a good answer for this without knowing your project back to front.

    Let me know how you go with the code

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

The topic ‘Get field values by group’ is closed to new replies.