Created
September 2, 2014 15:22
-
-
Save JodiWarren/dc9e95da3797409ead8d to your computer and use it in GitHub Desktop.
Advanced Custom Fields (ACF) get_field helper function
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
/** | |
* Simple boolean helper to check if ACF is on. | |
* @return boolean | |
*/ | |
function is_acf(){ | |
return function_exists( 'get_field' ) ? true : false; | |
} | |
/** | |
* Helper function for ACF get_field function | |
* @param string $field Field name | |
* @param integer $post_id Optionally pass the post ID | |
* @return varies Returns contents of get_field | |
*/ | |
function gf( $field, $post_id = null ) { | |
if ( ! is_acf() ) { | |
return false; | |
} | |
if ( get_field( $field, $post_id ) ) { | |
return get_field( $field, $post_id ); | |
} else { | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment