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://domain.com/movies/auto-draft/
as you noticed this is still navigating to post default title instead of Post Custom Meta box. Can you please let me know how I can update this to use an specific metabox , lets say $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] ) : '';
Update
Here is the code
function cpt_movie_post() {
$labels = array(
'name' => 'Movies',
'singular_name' => 'Movie',
'menu_name' => 'Movie',
'name_admin_bar' => 'Movie',
'parent_item_colon' => 'Parent Movie',
'all_items' => 'All Movie',
'view_item' => 'View Women ',
'add_new_item' => 'Add New Women ',
'add_new' => 'Add New Women ',
'new_item' => 'New Movie',
'edit_item' => 'Edit Moviee Item',
'update_item' => 'Update Movie Item',
'search_items' => 'Search Movie Item',
'not_found' => 'Moviee Not found',
'not_found_in_trash' => 'Moviee Not found in Trash',
);
$args = array(
'label' => 'Movie',
'description' => 'This Post Type Adds Movie to Website',
'labels' => $labels,
'supports' => array(''),
'taxonomies' => array( ),
'hierarchical' => true,
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'show_in_nav_menus' => true,
'show_in_admin_bar' => true,
'menu_position' => 5,
'menu_icon' => 'dashicons-layout',
'rewrite' => array( 'slug' => 'movie-post', 'with_front' => false ),
'can_export' => true,
'has_archive' => true,
'exclude_from_search' => false,
'publicly_queryable' => true,
'capability_type' => 'post',
);
register_post_type( 'movie_post', $args );
}
add_action( 'init', 'cpt_movie_post', 0 );
function movie_mtbox()
{
$post_types = array ( 'movie_post');
foreach( $post_types as $post_type ){
add_meta_box(
"product-detail",
"Movie Details ",
"render_movie_metas",
$post_type,
"normal",
"high"
);
}
}
function render_movie_metas( $post )
{
$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] ) : '';
}
add_action( 'save_post', 'we_metas_save' );
function we_metas_save( $post_id )
{
if( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return;
if( !isset( $_POST['meta_box_nonce'] ) || !wp_verify_nonce( $_POST['meta_box_nonce'], 'my_meta_box_nonce' ) ) return;
if( !current_user_can( 'edit_post' ) ) return;
$allowed = array(
'a' => array( // on allow a tags
'href' => array() // and those anchords can only have href attribute
)
);
// Probably a good idea to make sure your data is set
if( isset( $_POST['name_box'] ) ){
update_post_meta( $post_id, 'name_box', wp_kses( $_POST['name_box'], $allowed ) );
}
if( isset( $_POST['boxOffice_box'] ) ){
update_post_meta( $post_id, 'boxOffice_box', wp_kses( $_POST['boxOffice_box'], $allowed ) );
}
}
wp_insert_post()
as thepost_title
. If you can share the code you're using to create the posts it will be easier to plug that in so you have the full solution.wp_insert_post()
here? Thanks