Skip to content

Instantly share code, notes, and snippets.

@dgoze
Forked from JodiWarren/acf_gf_function.php
Created April 29, 2016 22:39
Show Gist options
  • Select an option

  • Save dgoze/ff0b8f16dfd55bb874d8496fe2b72a50 to your computer and use it in GitHub Desktop.

Select an option

Save dgoze/ff0b8f16dfd55bb874d8496fe2b72a50 to your computer and use it in GitHub Desktop.
Advanced Custom Fields (ACF) get_field helper function
/**
* 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