Modify Title using ACF/Save_Post
-
I’m using the form I had problems with earlier, and I hide the Title and Content fields on the frontend. I’m then trying to use the ACF/save_post to check it’s the particular post type, and take twoi fields from the form and update the title field.
The ACF Field Group is called ‘Font Pairings’. The code I’m using is as follows;
add_action( 'acf/save_post' , 'backend_after_save_post', 5);
function backend_after_save_post( $post_id ){
//if( ! isset( $_POST['acf'] ) ){
// return $_POST[‘_acf_post_id’];
//}
$posttype = get_post_type( $post_id );
debug_to_console($posttype);
if( get_post_type( $post_id ) == 'font parings' ) {
$firstfont = get_field('font_name',$post_id);
$pairfont = get_field('font_pair',$post_id);
$post_title = implode(' ',array_filter([$firstfont,'-',$pairfont])) ;
remove_action( 'acf/save_post', '_acf_do_save_post' );
$edit_post = array( 'ID' => $post_id, 'post_title' => $post_title );
$edit_post['post_name'] = sanitize_title( $post_title );
wp_update_post( $edit_post );
add_action( 'acf/save_post', '_acf_do_save_post' );
}
}Nothing is being changed, any ideas what I’m doing wrong?
Many thanks
Viewing 6 replies - 1 through 6 (of 6 total)
Viewing 6 replies - 1 through 6 (of 6 total)
- You must be logged in to reply to this topic.