将WordPress帖子和相关分类法移至自定义帖子类型&分类

时间:2012-04-19 18:10:54

标签: wordpress custom-post-type

我使用Twenty Eleven安装了一个干净的WordPress,没有插件或其他修改。该博客包含大约800个相关标签和类别的帖子。

我想将所有这些帖子移到自定义帖子类型中。通过将以下代码添加到我的functions.php中,我的博客现在已经安装了自定义帖子类型并且工作正常。

//Add custom post type
add_action( 'init', 'create_en_post_type' );
    function create_en_post_type() {
        register_post_type( 'en_post',  array(
            'labels' => array(
                'name' => __( 'English Posts' ),
                'singular_name' => __( 'English Post' )
            ),
            'public' => true,
            'menu_position' => 5,
            'rewrite' => array('slug' => 'en'),
            'supports' => array(
                'title', 
                'editor', 
                'author', 
                'excerpt', 
                'comments', 
                'custom-fields'
            )
        ));
    }

//Add belonging custom taxonomy
add_action( 'init', 'build_taxonomies', 0 ); 
    function build_taxonomies() { 
    register_taxonomy( 'english_categories', 'en_post', array( 'hierarchical' => true, 'label' => 'English Categories', 'query_var' => true, 'rewrite' => true ) );
    register_taxonomy( 'english_tags', 'en_post', array( 'hierarchical' => false, 'label' => 'English Tags', 'query_var' => true, 'rewrite' => true ) );
    }

现在我需要的是将常规帖子类型更改为我的自定义帖子类型。我已设法使用插件Convert Post Types移动帖子,但我的分类法未转换。

我意识到我可以创建类似的自定义类别并为其分配自定义帖子,但标签呢?如何转换这些(自动,1200个标签)?

我尝试在数据库中手动搞乱,但我无法使其正常工作。

1 个答案:

答案 0 :(得分:1)

您应该更改数据库中的ID,仔细查看phpmyadmin

  • wp_term_taxonomy
  • wp_terms
  • wp_term_relationships

在条款表中,您将找到旧的和新的taxamonies的id 在term_taxonomy中用新的替换所有旧的term_id

SQL:

UPDATE `wp_term_relationships` SET `term_id` = REPLACE(`term_id`, /*old id*/, /*new id*/);

在开始之前进行备份

相关问题