Home Forums ACF PRO Get 'meta key' from object


Get 'meta key' from object

  • Hey, there, I’m a developer and making a plugin for some ACF + WPML functionality.

    It’s purpose is to allow user adding a field translation directly from main version.
    So I made a button for each text/textarea/wysiwyg field with `acf.addAction(“ready_field/….. {
    ‘<div class=”pat_button button”>TRANSLATE</div>’

    which on click makes an ajax call and loads all the translated values by field key:

      jQuery(".pat_button").on("click", function () {
        var field_id = jQuery(this).parent().parent().attr("data-key");
        $post_id = $_POST['post_id'];
        $post_type = $_POST['post_type'];
        $field_id = $_POST['field_id'];
        $languages = apply_filters( 'wpml_active_languages', NULL, 'orderby=id&order=desc' );
        foreach($languages as $key => $value) {
            $languages[$key] = array();
            $languages[$key]['dest_post_id'] = apply_filters( 'wpml_object_id', $post_id, $post_type, FALSE, $key );
            $languages[$key]['dest_field_id'] = $field_id;
            $languages[$key]['field_val'] = get_field($field_id,$languages[$key]['dest_post_id']);
        echo json_encode($languages);

    It’s kinda working for top-level fields and I can see those textareas are filled with values properly:

    However, when it comes to nested inputs,textareas and wysiwyg inside repeaters or flexible content I get empty values. Probably because I have to conditionally use get_field and get_subfield for different inputs.

    However, how can I implement such conditional usage? It feels a bit complicated to use has_rows() for my case. is there a way to get ‘meta key’ with javascript api from so I can get_post_meta/update_post_meta instead of get_field/update_field?

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

You must be logged in to reply to this topic.