Support

Account

Home Forums General Issues How to convert field key to meta key

Solving

How to convert field key to meta key

  • Hi,

    I am trying to get dynamic value by field name . can any one support ??

    this is my field fields[field_5492be0701cb6][1][field_5492be5d01cb8][0][field_5492c04b01cbb][0][field_5492c13601cbf]

    but it’s stored in meta_key ==> recipe_sections_3_section_steps_0_step_ingredients_1_quantity

    get_filed(fields[field_5492be0701cb6][1][field_5492be5d01cb8][0][field_5492c04b01cbb][0][field_5492c13601cbf], $post->ID) not working

    how can i get..??

  • The question is, why are you trying to get the value using what you posted.

    Here’s an explanation of

    
    [field_5492be0701cb6]  // field key of recipe_sections
    [1]                    // row 1
    [field_5492be5d01cb8]  // field key of section_steps
    [0]                    // row 0
    [field_5492c04b01cbb]  // field key of step_ingredients
    [0]                    // row 0
    [field_5492c13601cbf]  // field key of quantity
    

    You can convert the field key to the field name this way

    
    $field = get_field_object($field_key);
    $field_name = $field['name'];
    

    Your field has 4 levels, a repeater or flex field, two nested repeaters or flex fields and whatever quantity is. ACF creates meta keys for repeaters like this:

    
    "{$field_name}_{$row}_{$field_name}_{$row}_{$field_name}_{$row}_{$field_name}"
    
  • thanks for your reply…

    am working ACF with WPML…

    am editing, your file ‘core/ field/text.php’

    for all other language, i want to display english as placeholder

    $english_recipe_id = icl_object_id($arabic_post_id,’recipe’,true,’en’);

    get_field($english_recipe_id,$field[‘name’]);

  • Well, that doesn’t really help me figure out what you need to do. I’m not very familiar with WPML. It’s also not my file. I just help out here on this support forum. However, editing one of the core files of the plugin isn’t usually a good idea, there are plenty of hooks in ACF and there are hooks in WPML as far as I know.

    Here’s an example of getting language independent values from ACF, it’s for options values but it can likely be adapted to use for other things as well. https://gist.github.com/senlin/4fd15ba7a19533ceb9fe

  • i will tell you… i just want solution with post_id + field key

    $post_id = 200
    print_r($field) = Array ( [key] => field_5492c13601cbf [label] => Quantity [name] => fields[field_5492be0701cb6][1][field_5492be5d01cb8][0][field_5492c04b01cbb][0][field_5492c13601cbf] [_name] => quantity [type] => text [order_no] => 1 [instructions] => [required] => 0 [id] => acf-field-field_5492be0701cb6_1_field_5492be5d01cb8_0_field_5492c04b01cbb_0_field_5492c13601cbf [class] => text [conditional_logic] => Array ( [status] => 0 [rules] => Array ( ) [allorany] => all ) [column_width] => 20 [default_value] => [placeholder] => [prepend] => [append] => [formatting] => html [maxlength] => [value] => 50 )

    get_field($field[‘name’],$english_recipe_id); will it work ..??

  • over all , i want to get the nested single field value without any loop

    get_field(‘field_5492be0701cb6_1_field_5492be5d01cb8_0_field_5492c04b01cbb_1_field_5492c13601cbf’,$post_id);

    ??

  • I don’t think there is any way to get the value of a nested field without doing some type of a loop. Like you requested in your first post, you’re going to need to convert each field key to a field name and you’re going to need to extract the field keys in order to do that. I can’t think of any way to do this without using a loop.

Viewing 7 posts - 1 through 7 (of 7 total)

The topic ‘How to convert field key to meta key’ is closed to new replies.