I tried this function but it doesn’t save the title when i create a new post of post type “pelatologio” but it does save the title if i open the new post and save it again
add_action('acf/save_post', 'cst_check_post_title', 20);
function cst_check_post_title($post_id) {
if (!is_numeric($post_id)) {
return;
}
$post_type = get_post_type($post_id);
if ($post_type == 'pelatologio'){
$cst_t_date=date("d/m/Y", strtotime($_POST['acf']['field_5a6b3543bf97a']));
$cst_epi = get_field('epitheto');
$cst_pat = get_field('onoma_patros');
$cst_ono = get_field('onoma');
$cst_title =$cst_epi.' '.mb_strimwidth($cst_pat, 0, 3 ).' '.$cst_ono.' '.$cst_t_date;
$data['post_title'] = $cst_title;
}else if ($post_type == 'parastatika'){
$data['post_title'] = 'Απόδειξη Παροχής Υπηρεσιών #';
}
wp_update_post( $data );
}
i tried using the $_POST[‘acf’] way as well but that one doesn’t seem to work either with the acf/save_post for the initial save i have considered using acf/save_post with $_POST[‘acf’] and lower the priority to 10 and see if that would work for both New Posts and Updated Posts
I guess i need two seperate functions, one for the new posts and one for the posts being updated, i suppose i can keep my function as is and add a condition to check if the post is new and a seperate function that uses the acf/save_post and run this one for published post.
Does this sound correct to you?
Thanks for your assistance!
Solved it , wrapped repeater sub fields in an accordion custom field
This did the trick for me!
basically i used this to get the first 3 characters: mb_strimwidth($_POST['acf']['field_5a6b343038f0c'], 0, 3 )
Below you can see the function:
function acf_review_before_save_post($post_id) {
if (empty($_POST['acf']))
return;
$_POST['acf']['_post_title'] =$_POST['acf']['field_5a6770a3c509d'].' '.mb_strimwidth($_POST['acf']['field_5a6b343038f0c'], 0, 3 ).' '.$_POST['acf']['field_5a5f76d271881'].' '.date("d/m/Y", strtotime($_POST['acf']['field_5a6b3543bf97a']));
return $post_id;
}
add_action('acf/pre_save_post', 'acf_review_before_save_post', -1);
Thanks for your response!
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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.