Wordpress-将帖子*和类别*一起移动到自定义的帖子类型



TLDR:我已经能够将1000篇文章从posts批量迁移到我创建的自定义文章类型"News",但需要将旧类别映射到我创建了的新分类法。我还有其他博客文章,所以不想移动所有类别,只是一些。

我所做的(下面的代码(:-创建自定义帖子类型("新闻"(-为自定义帖子类型创建了类别分类法(也称为"类别"(-使用"帖子类型切换器"将帖子迁移到新闻

需要做的事情:-在新闻页面上显示帖子的相同类别。

functions.php:


function cw_post_type_news() {
$supports = array(
'title', // post title
'editor', // post content
'author', // post author
'thumbnail', // featured images
'excerpt', // post excerpt
'custom-fields', // custom fields
'comments', // post comments
'revisions', // post revisions
);
$labels = array(
'name' => _x('News', 'plural'),
'singular_name' => _x('News', 'singular'),
'menu_name' => _x('News', 'admin menu'),
'name_admin_bar' => _x('News', 'admin bar'),
'add_new' => _x('Add New', 'add new post'),
'add_new_item' => __('Add New news'),
'new_item' => __('New news'),
'edit_item' => __('Edit news'),
'view_item' => __('View news'),
'all_items' => __('All news'),
'search_items' => __('Search news'),
'not_found' => __('No news found.'),
);
$args = array(
'supports' => $supports,
'labels' => $labels,
'public' => true,
'query_var' => true,
'menu_position' => 5,
'rewrite' => array('slug' => 'news'),
'has_archive' => true,
'hierarchical' => false,
);
register_post_type('news', $args);
}
add_action('init', 'cw_post_type_news');
/* Add categories (custom taxonomy) for news =============================== */
function my_taxonomies_news() {
$labels = array(
'name'              => _x( 'Categories', 'taxonomy general name' ),
'singular_name'     => _x( 'Category', 'taxonomy singular name' ),
'search_items'      => __( 'Search Categories' ),
'all_items'         => __( 'All Categories' ),
'parent_item'       => __( 'Parent Category' ),
'parent_item_colon' => __( 'Parent Category:' ),
'edit_item'         => __( 'Edit Category' ),
'update_item'       => __( 'Update Category' ),
'add_new_item'      => __( 'Add New Category' ),
'new_item_name'     => __( 'New Category' ),
'choose_from_most_used' => __( 'Choose from the most used categories', 'textdomain' ),
'menu_name'         => __( 'Categories' ),
);
$args = array(
'labels' => $labels,
'hierarchical' => true,
'show_ui'           => true,
'show_admin_column' => true,
);
register_taxonomy( 'news_category', 'news', $args );
}
add_action( 'init', 'my_taxonomies_news', 0 );

这很容易。您只需要从管理面板>工具>导出导出所有帖子。您可以按照以下步骤操作:将WORDPRESS邮件导出到自定义邮件类型

我也遵循了同样的步骤。试试看,如果你需要我的帮助,请告诉我。

最新更新