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'])) {
return;
}
// 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.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.