Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

When an admin saves a post from my custom post type jobs, i do not want the content field(the large 'description' field) from saving.

To explain - when an admin saves a post from the jobs post type all the custom fields, date field etc. should save but the standard content field should stay the same without being saved.

I've found the pre_post_update hook, but i do not know what to do now.

This is my code so far.

add_action( 'pre_post_update', 'prefix_prevent_job_description_admin_save' );
function prefix_prevent_job_description_admin_save( $post_id, $data ) {
   
   if ( 'jobs' !== get_post_type( $post_id ) ) return;

   // Here i should probably use the $data array to get the content and prevent it from saving, but i do not know how to go from here.

}

Thanks in advance.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
231 views
Welcome To Ask or Share your Answers For Others

1 Answer

you need to do it with a filter instead of an action, i think you can do this with the this filter wp_insert_post_data

https://developer.wordpress.org/reference/hooks/wp_insert_post_data/


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...