I have a problem, my custom title keeps getting added at every time I save the post..
First I created a Custom Post Type called 'imac' plus a front-end form for posting in this Post Type, only before saving I would like to change the ['post_title'] based on the Custom Fields people fill out on the front-end form aswel.
Every post people create front-end will get a 'pending' post_status but as soon as I press Publish or edit the post later and press update the title gets added too. for example: example.com/imac-lala-blabla/ becomes after a second save: example.com/imac-lala-blabla-lala-blabla/
Can somebody help me please.
function modify_imac_title( $post_id ) {
// ['post_title'] create $vars for custom title setup
$ghz = get_post_meta( $post_id, 'imac_processor', true );
$strip_ghz = preg_replace( '/z.*$/', 'z', $ghz );
$ram = get_post_meta( $post_id, 'imac_ram', true );
$hd = get_post_meta( $post_id, 'imac_harddrive', true );
$model = get_post_meta( $post_id, 'imac_model', true );
global $wpdb;
$wpdb->update( $wpdb->posts,
array(
'post_title' => get_the_title( $post_id ).' '.$strip_ghz.' '.$ram.'GB '.$hd.' '.$model
),
array( 'ID' => $post_id )
);
}
add_action( 'save_post_imac', 'modify_imac_title' );