I want to update the post meta of a custom post type when a user updates the custom post type's title in the admin backend. Something like the pseudo code below;

if ((get_the_title() !== $val_in_title_field) && (Publish == true)) 
    update_post_meta( $id, 'custom_field', '' );

I am not clear on how to check what is passed from the title field when a user clicks publish and all how to check if a uer has clicked publish.

  • Are you referring to a custom post type by saying "custom posts"? And please explain your question as it is unclear. – Domain Oct 31 '14 at 12:01
  • @WisdmLabs Yes and done – myol Oct 31 '14 at 12:07

Try this out,

add_filter( 'wp_insert_post_data' , 'modify_post_title' , '50', 2 );

function modify_post_title( $data , $postarr )
  if($data['post_type'] == '{custom post type}') {
      if($data['post_title'] == $postarr['post_title']){
            update_post_meta( $data["ID"], 'custom_field', '' );
  return $data;

Reference: https://wordpress.org/support/topic/modifying-title-before-saving-custom-post

  • Looking up the codex seems to confirm this answer, but word-press doesn't seem to call the filter function for me... – myol Oct 31 '14 at 15:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.