1
votes

I have a custom Post Type which is not using any of WP builtin supports (like 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments'). Instead I am using my own metaboxes to publish the CPT. Now after creating the CPT and publishing when I click on the View Post it navigates to a URL ending with auto-draft and on second CPT to auto-draft-2 and so on

http://localhost/movies/auto-draft/

As you noticed this is still navigating to post default title instead of Post Custom Meta box. How can I update this to use an specific metabox, such as $name?

$we_movieMetas = get_post_custom( $post->ID );
$name = isset( $we_movieMetas['name_box'] ) ? esc_attr( $we_movieMetas['name_box'][0] ) : '';
$boxOffice = isset( $we_movieMetas['boxOffice_box'] ) ? esc_attr( $we_movieMetas['boxOffice_box'][0] ) : '';
1
why would you not want to use title?rudtek
@rudtek Title is not necessary for this cpt I believe.Alexander Behling

1 Answers

0
votes

You have to prevent autosave via the save_post-hook (@see https://developer.wordpress.org/reference/hooks/save_post/).

First of all you have to ensure that the saving is for your cpt. Then you could check if it is an autosave via wp_is_post_autosave. Also you could check if it is a revision being restore (only if you cpt supports it) via the function wp_is_post_revision.

Also you could deregister the default saving metabox via a snippet like this:

function custom_metaboxes(){
/* Remove the publishing metabox */
    remove_meta_box( 'submitdiv', 'your-cpt', 'side' );
...
}
add_action('add_meta_boxes','custom_metaboxes');

For the original saving box have a look into wp-admin/includes/meta-boxes.php and search for post_submit_meta_box.