Last active
December 19, 2015 21:58
-
-
Save hereswhatidid/6023589 to your computer and use it in GitHub Desktop.
Extends the default Advanced Custom Fields get_field function to allow options for a default value and fallback to global options value.
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
<?php | |
if ( ! function_exists( 'get_field_ext' ) && ( function_exists( 'get_field' ) ) ) { | |
/** | |
* Extends the default ACF get_field function to allow options for a default value and fallback to global option | |
* | |
* @author Gabe Shackle <gabe@hereswhatidid.com> | |
* @param string $name Field name | |
* @param mixed $default Default value if none found | |
* @param integer $id Post ID to check the field value of | |
* @return mixed Value after running checks | |
*/ | |
function get_field_ext( $name = '', $default = null, $id = null ) { | |
if ( ! empty( $id ) ) { | |
if ( $result = get_field( $name, $id ) ) { | |
return $result; | |
} | |
} else { | |
if ( ( $result = get_field( $name ) ) || ( $result = get_field( $name, 'options' ) ) ) { | |
return $result; | |
} | |
} | |
return $default; | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment