将WordPress帖子和相关分类法移动到自定义帖子类型和分类 [英] Move WordPress posts and related taxonomy to custom post type & taxonomy

查看:68
本文介绍了将WordPress帖子和相关分类法移动到自定义帖子类型和分类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a clean WordPress installation using Twenty Eleven, with no plugins or other modifications. The blog contains approximately 800 posts with related tags and categories.

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

I'd like to move all these posts to a custom post type. By adding the following code to my functions.php my blog now has the custom post type installed and working perfectly.

//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 ) );
    }

现在我所需要做的就是将常规帖子类型更改为自定义帖子类型。我设法使用插件转换帖子类型来移动帖子,但是我的分类法没有转换。

Now all I need is to change the regular post type to my custom post type. I've managed to move the posts using the plugin Convert Post Types, but my taxonomies aren't converted.

我知道我可以创建类似的自定义类别并为其分配自定义帖子,但是标签呢?我该如何转换它们(自动生成1200个标签)?

I realize I could just create similar custom categories and assign the custom posts to them, but what about tags? How can I convert these (automatically, 1200 tags)?

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

I've tried manually messing around in the database, but I can't make it work.

推荐答案

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

You should change the ID's in the database, take a long look at the phpmyadmin


  • wp_term_taxonomy

  • wp_terms

  • wp_term_relationships

在条款表中,您会找到旧分类法和新分类法的ID。

在term_taxonomy中替换所有旧的 term_id

In the terms table you will find the id of the old and new taxamonies
in term_taxonomy replace all old term_id with the new.

SQL:

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

在开始之前做备份

这篇关于将WordPress帖子和相关分类法移动到自定义帖子类型和分类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆