How can I stop my custom posts saving with the title ‘Auto Draft’? I’ve tried the code below to save my Book_Title
custom field as the post-title
but to no success:
if(isset($_POST['Book_Title'])){
update_post_meta($post_id,'post_title', sanitize_text_field($_POST['Book_Title']));
} else {
delete_post_meta( $post_id, 'Book_Title' );
}
3
Answers
please you test for stop Auto Draft :
define( ‘WP_POST_REVISIONS’, false ); //in wp-config.php
if you use metabox :
1-
2-
}
3-
4-
If you are simply trying to change the default post_title WordPress uses when creating an auto-draft for your custom post type, the sample code below should work when added to a plugin or child theme. The code will only change the default Auto Draft post title for the identified custom post type while continuing to use "Auto Draft" for other post types. If you are trying to accomplish more than this, please explain further by updating your question or responding with a comment.
Like many WordPress hooks, the
title_save_pre
filter hook does not yet have a dedicated documentation page on wordpress.org.If you are not familiar with creating your own plugin, you can refer to the WordPress Plugin Handbook and WordPress Plugin Basics.
Sample code
You can add this code in config file as per your need.