我有一个自定义的帖子类型,它没有使用任何WP内置支持,如(\'标题\'、\'编辑器\'、\'作者\'、\'缩略图\'、\'摘录\'、\'注释\')。相反,我使用自己的元数据库来发布CPT。现在,在创建CPT并发布之后,当我单击查看帖子时,它会导航到以auto-draft 在第二次CPT上auto-draft-2 等等
http://domain.com/movies/auto-draft/
正如您所注意到的,这仍然是导航到发布默认标题,而不是发布自定义元框。你能告诉我如何更新这个以使用特定的metabox吗$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
这是代码
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 ) );
}
}