Support

Account

Home Forums Add-ons Flexible Content Field How to get the sub-field key names

Solving

How to get the sub-field key names

  • Hi, I’d like to be able to get at the unique meta-key name for a sub field within a flexible content area (or a repeater).

    Ideally what I’d like to do is call get_sub_field_object() and have returned in the array the meta_key name that corresponds to the unique custom field name (i.e. “custom_content_1_content”) but can’t figure out how to do it.

    I’d eventually like to do something like this so that I can pass the name of the custom field to another plugin to update:

    
    <?php 
    $col = get_sub_field_object("left_column"); 
    $colKey = $col["unique-key"];
    ?>
    
    <div class="custom" id="col1" pid="<?php echo $page_id; ?>" custom-field-name="<?php echo $colKey; ?>">
      <?php the_sub_field("left_column"); ?>
    </div >
    

    Any help you can give would be very welcome.

    Thanks,
    Gregor

  • Hi @gspowart

    There is no function to retrieve the actual postmeta meta_name value.
    However, you can use some simple logic to find it.

    The pattern to find the meta_name is:
    $parentName_$rowIndex_$childName

    If you know the parent field name and the child field name, this is a simple task. You can find the row index by using a counter in your loop.

    Feel free to paste up any code you are having trouble with it.

    Thanks
    E

  • Hi Elliot,

    Great, that’ll work for me. I’ll give it a try. Thanks for the prompt reply!

    Cheers,
    Gregor

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

The topic ‘How to get the sub-field key names’ is closed to new replies.