Home Forums General Issues Merge multiple fields value to one Reply To: Merge multiple fields value to one

  • This code is un-tested as of now, but your best bet would be to use the acf/save_post hook, most likely:

    function merge_post_values($post_id) {
        if (empty($_POST['acf'])) {
        // Run some logic to determine whether or not the current post is
        // correct -- for example, based on the ID, template, post type, etc.
        if ($post_id == 1) {
            $merged_values = [];
            if (isset($_POST['value_1'])) {
                $merged_values[] = $_POST['value_1'];
            if (isset($_POST['value_2'])) {
                $merged_values[] = $_POST['value_2'];
            update_post_meta($post_id, 'merged_values', $merged_values);
    add_action('acf/save_post', 'merge_post_values', 1);

    I’ve not included any sanitation and I’m not entirely sure how your structure is setup (for example, if the values are strings, arrays, so on), or how they need to be saved, but the above should be enough of a premise to work on for saving the values as a separate piece of post meta.