Custom page title on saving post
-
I have created a custom post type with Pods. Now I want to generate the page title based on Pods values of the post. I created a small function for this:
function set_car_title( $data , $postarr ) { if($data['post_type'] == 'auto') { $pod = pods( 'auto', get_the_id() ); $merk = $pod->display('automerk'); $model = $pod->display('automodel'); $data['post_title'] = $merk." ".$model; $data['post_name'] = $merk." ".$model; } return $data; } add_filter( 'wp_insert_post_data' , 'set_car_title' , '10', 2 );
This works fine when I update the custom post but not when creating a new one. So if I create a new custom post it does not work but when i update it the title gets set.
I think it’s because the pods function runs before there is an id assigned. Anyone any ideas on how to fix this?
Viewing 5 replies - 1 through 5 (of 5 total)
Viewing 5 replies - 1 through 5 (of 5 total)
- The topic ‘Custom page title on saving post’ is closed to new replies.