【问题标题】:Wordpress - Move posts *along with categories* to a custom post typeWordpress - 将帖子*连同类别*移动到自定义帖子类型
【发布时间】:2020-04-24 02:06:55
【问题描述】:

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】:

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

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

    【讨论】:

      猜你喜欢
      • 2011-11-19
      • 2011-06-24
      • 1970-01-01
      • 2012-01-01
      • 2019-01-23
      • 2014-07-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多