Пример #1
0
function _acf_get_field_by_key($key = '', $db_only = false)
{
    // try JSON before DB to save query time
    if (!$db_only && acf_is_local_field($key)) {
        return acf_get_local_field($key);
    }
    // vars
    $post_id = acf_get_field_id($key);
    // bail early if no post_id
    if (!$post_id) {
        return false;
    }
    // return
    return _acf_get_field_by_id($post_id, $db_only);
}
Пример #2
0
function acf_get_local_field($key)
{
    // bail early if no field
    if (!acf_is_local_field($key)) {
        return false;
    }
    // return
    return acf_local()->fields[$key];
}
Пример #3
0
function _acf_get_field_by_key($key = '', $db_only = false)
{
    // try JSON before DB to save query time
    if (!$db_only && acf_is_local_field($key)) {
        $field = acf_get_local_field($key);
        // validate
        $field = acf_get_valid_field($field);
        // return
        return $field;
    }
    // vars
    $post_id = acf_get_field_id($key);
    // validate
    if (!$post_id) {
        return false;
    }
    // return
    return _acf_get_field_by_id($post_id, $db_only);
}
Пример #4
0
function _acf_get_field_by_key($key = '')
{
    // vars
    $field = false;
    // try JSON before DB to save query time
    if (acf_is_local_field($key)) {
        $field = acf_get_local_field($key);
        // validate
        $field = acf_get_valid_field($field);
        // return
        return $field;
    }
    // vars
    $args = array('posts_per_page' => 1, 'post_type' => 'acf-field', 'orderby' => 'menu_order title', 'order' => 'ASC', 'suppress_filters' => false, 'acf_field_key' => $key);
    // load posts
    $posts = get_posts($args);
    // validate
    if (empty($posts)) {
        return $field;
    }
    // load from ID
    $field = _acf_get_field_by_id($posts[0]->ID);
    // return
    return $field;
}
 function add_field($field)
 {
     // validate
     $field = acf_get_valid_field($field);
     // don't allow overrides
     // edit: some manually created fields (via .php) used duplicate keys (copy of origional field).
     /*
     if( acf_is_local_field($field['key']) ) {
     			
     			return;	
     			
     		}
     */
     // vars
     $parent = $field['parent'];
     // append $parents
     $this->parents[$parent][] = $field['key'];
     // add in menu order
     $field['menu_order'] = count($this->parents[$parent]) - 1;
     // find ancestors
     //$field['ancestors'] = array();
     while (acf_is_local_field($parent)) {
         //$field['ancestors'][] = $parent;
         $parent = acf_get_local_field($parent);
         $parent = $parent['parent'];
     }
     //$field['ancestors'][] = $field['field_group'];
     // add field
     $this->fields[$field['key']] = $field;
 }