Created
June 24, 2013 08:19
-
-
Save dechowdev/5848536 to your computer and use it in GitHub Desktop.
ACF Retrieve Field object:
http://support.advancedcustomfields.com/discussion/290/field-label-on-frontend/p1 Code by Elliot Condon. This is simply a port, and showcase of the code, for reference by you and me.
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 | |
function get_field_object($field_name,$post_id = false) | |
{ | |
global $post, $acf; | |
if(!$post_id) | |
{ | |
$post_id = $post->ID; | |
} | |
// allow for option == options | |
if( $post_id == "option" ) | |
{ | |
$post_id = "options"; | |
} | |
// get value | |
$field_key = ""; | |
if( is_numeric($post_id) ) | |
{ | |
$field_key = get_post_meta($post_id, '_' . $field_name, true); | |
} | |
else | |
{ | |
$field_key = get_option('_' . $post_id . '_' . $field_name); | |
} | |
// default return vaue | |
$field = false; | |
if($field_key != "") | |
{ | |
// we can load the field properly! | |
$field = $acf->get_acf_field( $field_key ); | |
} | |
return $field; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment