get_field_reference
Get_field_reference().
Description
This function will find the $field_key
that is related to the $field_name
. This is know as the field value reference
Parameters (2)
- 0. $field_name (string)
- The field name.
- 1. $post_id
- The post id.
Usage
if ( !function_exists( 'get_field_reference' ) ) { require_once ABSPATH . PLUGINDIR . 'advanced-custom-fields/core/api.php'; } // The field name. $field_name = ''; // The post id. $post_id = null; // NOTICE! Understand what this does before running. $result = get_field_reference($field_name, $post_id);
Defined (1)
The function is defined in the following location(s).
- /core/api.php
- function get_field_reference( $field_name, $post_id ) {
- // cache
- $found = false;
- $cache = wp_cache_get( 'field_reference/post_id=' . $post_id . '/name=' . $field_name, 'acf', false, $found );
- if( $found )
- {
- return $cache;
- }
- // vars
- $return = '';
- // get field key
- if( is_numeric($post_id) )
- {
- $return = get_post_meta($post_id, '_' . $field_name, true);
- }
- elseif( strpos($post_id, 'user_') !== false )
- {
- $temp_post_id = str_replace('user_', '', $post_id);
- $return = get_user_meta($temp_post_id, '_' . $field_name, true);
- }
- else
- {
- $return = get_option('_' . $post_id . '_' . $field_name);
- }
- // set cache
- wp_cache_set( 'field_reference/post_id=' . $post_id . '/name=' . $field_name, $return, 'acf' );
- // return
- return $return;
- }