Home › Forums › ACF PRO › Check post type before publishing post › Reply To: Check post type before publishing post
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
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.