Skip to content

Commit

Permalink
3.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
timothyjensen committed Oct 14, 2020
1 parent b66d7b7 commit 322b1b0
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 60 deletions.
12 changes: 8 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
# Change Log for ACF Field Group Values

## 3.2.0 - 2020-10-14
### Added
- Added support for returning field labels along with values.

## 3.1.0 - 2018-12-26
### Added
- Added support for user meta - props @Boldairdev.

## 3.0.0 - 2018-07-21
### Changed
- Changed array keys used for storing clone fields to be more consistent with how ACF stores the meta in the database. **This is a breaking change for those using clone fields.**
- Update tests to reflect the change related to storing clone field values
- Changed array keys used for storing clone fields to be more consistent with how ACF stores the meta in the database. **This is a breaking change for those using clone fields.**
- Update tests to reflect the change related to storing clone field values
- Renamed test data directory

### Added
Expand Down Expand Up @@ -59,7 +63,7 @@

## 2.0.0 - 2017-11-17
### Changed
- The second argument passed to `get_all_custom_field_meta()` must include the field key; pass `$config` instead of
- The second argument passed to `get_all_custom_field_meta()` must include the field key; pass `$config` instead of
`$config['fields']`.
- Bumped PHP requirement to 7.0+.

Expand All @@ -76,7 +80,7 @@

### Added
- Refactored into a class.
- Support for custom fields stored as options.
- Support for custom fields stored as options.
- Published as a composer package and WordPress plugin.

## 1.2.5 - 2017-10-19
Expand Down
142 changes: 87 additions & 55 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[![PHP Version](https://img.shields.io/badge/php-7.0%2B-blue.svg)](https://packagist.org/packages/timothyjensen/acf-field-group-values)
[![Build Status](https://travis-ci.org/timothyjensen/acf-field-group-values.svg?branch=master)](https://travis-ci.org/timothyjensen/acf-field-group-values)
[![PHP Version](https://img.shields.io/badge/php-7.0%2B-blue.svg)](https://packagist.org/packages/timothyjensen/acf-field-group-values)
[![Build Status](https://travis-ci.org/timothyjensen/acf-field-group-values.svg?branch=master)](https://travis-ci.org/timothyjensen/acf-field-group-values)
[![codecov](https://codecov.io/gh/timothyjensen/acf-field-group-values/branch/master/graph/badge.svg)](https://codecov.io/gh/timothyjensen/acf-field-group-values)

# ACF Field Group Values
Expand All @@ -15,7 +15,7 @@ The recommended way to install this component is with Composer:
composer require timothyjensen/acf-field-group-values
```

Alternatively, you can download the latest release and install it like a typical WordPress plugin.
Alternatively, you can download the latest release and install it like a typical WordPress plugin.

## Usage

Expand All @@ -25,110 +25,142 @@ As of version 2.0.0 the `$config` argument must contain all data from the acf fi

```php
<?php

// Replace with the name of your field group JSON.
$field_group_json = 'group_59e226a200966.json';

$config = json_decode( file_get_contents( PATH_TO_ACF_JSON . $field_group_json ), true );
```

1. Build an array containing all post meta for the specified field group:

```php
<?php

$acf_post_meta = get_all_custom_field_meta( get_the_ID(), $config );
```

1. Build an array containing all option values for the specified field group:

```php
<?php

$acf_option_values = get_all_custom_field_meta( 'option', $config );
```

1. Build an array containing all term meta for the specified field group:

```php
<?php

$term_id = 'term_2';

$acf_term_values = get_all_custom_field_meta( $term_id, $config );
```

1. Build an array containing all user meta for the specified field group:

```php
<?php

$user_id = 'user_2';

$acf_user_values = get_all_custom_field_meta( $user_id, $config );
```

1. In order to retrieve values for clone fields you must pass a third argument: all field group arrays that contain the fields that will be cloned.

```php
<?php

// Replace with the names of your field group JSONs.
$clone_json_1 = 'group_59e226a200967.json';
$clone_json_2 = 'group_59e226a200968.json';

$clone_fields = [
json_decode( file_get_contents( PATH_TO_ACF_JSON . $clone_json_1 ), true ),
json_decode( file_get_contents( PATH_TO_ACF_JSON . $clone_json_2 ), true )
];

$acf_post_meta = get_all_custom_field_meta( get_the_ID(), $config, $clone_fields );
```

1. As of version 3.2 you can include field labels along with values in the results.

```php
<?php

// Passing 'true' as the fourth argument will include field labels in the results.
$acf_post_meta = get_all_custom_field_meta( get_the_ID(), $config, [], true );

/* The above results in:
'group' => [
'group_1' => [
'label' => 'Group 1 Label',
'value' => 'Group 1',
],
'group_2' => [
'label' => 'Group 2 Label',
'value' => 'Group 2',
],
'subgroup' => [
'subgroup1' => [
'label' => 'Subgroup 1 Label',
'value' => 'Subgroup 1',
],
'subgroup2' => [
'label' => 'Subgroup 2 Label',
'value' => 'Subgroup 2',
],
],
]
*/
```

## Example Results

In the test results below `get_all_custom_field_meta()` was 600% faster than `get_field()` and required 19 fewer database queries. Note that the returned values are raw meta values as opposed to formatted values that can be returned by `get_field()`.
In the test results below `get_all_custom_field_meta()` was 600% faster than `get_field()` and required 19 fewer database queries. Note that the returned values are raw meta values as opposed to formatted values that can be returned by `get_field()`.

```php
<?php

$results = [
'group' => [
'group_1' => 'Group 1',
'group_2' => 'Group 2',
'subgroup' => [
'subgroup1' => 'Subgroup 1',
'subgroup2' => 'Subgroup 2',
],
],
'repeater' => [
[
'repeater_sub_field' => 'Sub Field',
'repeater_2' => [
[
'repeater_2_subfield' => 'Level 2 subfield',
],
[
'repeater_2_subfield' => 'Level 2 subfield',
],
],
],
],
'flexible_content' => [
[
'acf_fc_layout' => 'flex_content_type_1',
'flex_content_field' => 'Flex content type 1',
],
[
'acf_fc_layout' => 'flex_content_type_2',
'flex_content_field' => 'Flex content type 2',
],
],
// The following are cloned fields.
'group_1' => 'Cloned group 1',
'subgroup' => [
'subgroup1' => 'Cloned subgroup 1',
'subgroup2' => 'Cloned subgroup 2',
],
'group' => [
'group_1' => 'Group 1',
'group_2' => 'Group 2',
'subgroup' => [
'subgroup1' => 'Subgroup 1',
'subgroup2' => 'Subgroup 2',
],
],
'repeater' => [
[
'repeater_sub_field' => 'Sub Field',
'repeater_2' => [
[
'repeater_2_subfield' => 'Level 2 subfield',
],
[
'repeater_2_subfield' => 'Level 2 subfield',
],
],
],
],
'flexible_content' => [
[
'acf_fc_layout' => 'flex_content_type_1',
'flex_content_field' => 'Flex content type 1',
],
[
'acf_fc_layout' => 'flex_content_type_2',
'flex_content_field' => 'Flex content type 2',
],
],
// The following are cloned fields.
'group_1' => 'Cloned group 1',
'subgroup' => [
'subgroup1' => 'Cloned subgroup 1',
'subgroup2' => 'Cloned subgroup 2',
],
];
```
2 changes: 1 addition & 1 deletion acf-field-group-values.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* Author URI: https://www.timjensen.us
* Text Domain: acf-field-group-values
* Domain Path: /languages
* Version: 3.1.0
* Version: 3.2.0
*
* @package TimJensen\ACF\Field_Group_Values
* @license GPL-3.0-or-later
Expand Down

0 comments on commit 322b1b0

Please sign in to comment.