I have a field, for example: deatils.
The post title has a pattern, for example: Title – details. It has two parts, the separator is a ‘-‘ character. The first part is only a prefix, but the second is important for other reasons.
How can I copy only the second part to the ‘details’ field?
I tried with this code snippet, but it didn’t work.
function my_custom_title_operation( $value, $post_id, $field ) {
$title = get_the_title($post_id);
if (strpos($title, '-') !== false) {
$parts = explode('-', $title, 2);
if (isset($parts[1])) {
$after_dash = trim($parts[1]);
add_post_meta($post_id, 'details', $after_dash);
}
}
return $value;
}
add_filter('acf/update_value/name=details', 'my_custom_title_operation', 10, 3);