Wordpress-将帖子*以及类别*移至自定义帖子类型

问题描述 投票:0回答:1

TLDR:我已经能够将1,000个帖子从“帖子”批量迁移到我创建的“新闻”自定义帖子类型,但是需要将旧类别映射到我创建的新分类法。我还有其他博客文章,所以不想只移动某些类别。

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

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

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
1个回答
0
投票

很容易。您只需要从管理控制台>工具>导出中导出所有帖子。您可以按照以下步骤操作:EXPORT WORDPRESS POSTS TO CUSTOM POST TYPE

我遵循了相同的步骤。尝试一下,让我知道您是否需要我的帮助。

© www.soinside.com 2019 - 2024. All rights reserved.