-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
updated README.md
- Loading branch information
Jan Horecny
committed
Aug 23, 2017
1 parent
2547286
commit d89af5b
Showing
2 changed files
with
42 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
/** | ||
* Return values as key => value paired array based on specific field names | ||
* | ||
* Example: $fields = get_custom_fields(['field1', 'field2']); | ||
* | ||
* @version 1.0.0 | ||
* @link https://www.advancedcustomfields.com/resources/get_field/ | ||
* @author Jan Horecny <[email protected]> | ||
* @todo add support for post IDs | ||
* | ||
* @param bool|array $fields | ||
* @param bool $includeBlank | ||
* | ||
* @return bool|array | ||
*/ | ||
function get_custom_fields( $fields = false, $includeBlank = true ) { | ||
if ( ! is_array( $fields ) ) { | ||
return false; | ||
} | ||
|
||
$values = false; | ||
|
||
foreach ( $fields as $field ) { | ||
if ( get_field( $field ) ) { | ||
$values[ $field ] = get_field( $field ); | ||
} elseif ( $includeBlank ) { | ||
$values[ $field ] = ''; | ||
} | ||
} | ||
|
||
return $values; | ||
} |