如何在WordPress中导入和导出自定义帖子类型

It is extremely easy to move your WordPress site using a backup plugin. But what if you only wanted to move a custom post type? In this article, we will show you how to import and export custom post types in WordPress. We will also show you how to import any custom taxonomies associated with your post types.

使用备份插件移动WordPress网站非常容易。 但是,如果您只想移动自定义帖子类型怎么办? 在本文中,我们将向您展示如何在WordPress中导入和导出自定义帖子类型。 我们还将向您展示如何导入与您的帖子类型相关的任何自定义分类法。

There are two steps involved in exporting and importing a custom post type in WordPress. First step involves migrating the actual custom post type and taxonomies. The second step is to import the post type data.

在WordPress中导出和导入自定义帖子类型涉及两个步骤。 第一步涉及迁移实际的自定义帖子类型和分类法。 第二步是导入帖子类型数据。

Often custom post types in WordPress are associated with their own custom taxonomies. We will show you how to export/import your custom taxonomies along with your post type.

WordPress中的自定义帖子类型通常与它们自己的自定义分类法相关联。 我们将向您展示如何导出/导入自定义分类法以及您的帖子类型。

Migrate Custom Post Types
在WordPress中导出自定义帖子类型和分类法 (Exporting Custom Post Types and Taxonomies in WordPress)

Some users prefer to create their custom post types and taxonomies by adding code in their theme’s functions.php file or a site-specific plugin. In that case, all you need to do is copy that code and paste it on the site where you want to import them.

一些用户更喜欢通过在主题的functions.php文件或特定站点的插件中添加代码来创建其自定义帖子类型和分类法。 在这种情况下,您要做的就是复制该代码并将其粘贴到要导入它们的站点上。

However, in some cases you may not be able to locate the code. Don’t worry you can still create the same custom post type on the new site.

但是,在某些情况下,您可能无法找到代码。 不用担心,您仍然可以在新网站上创建相同的自定义帖子类型。

All you need to know is the post key value. This is the name used for the post type in your WordPress database. You can find it by simply visiting the post type in your WordPress admin area.

您需要知道的只是职位的关键值。 这是用于WordPress数据库中帖子类型的名称。 您只需访问WordPress管理区域中的帖子类型即可找到它。

Getting the post type key

Once you have the post key, visit the site where you want to import the post type and use Custom Post Types UI plugin to create your custom post type.

拥有发布键后,请访问您要在其中导入发布类型的网站,并使用“ 自定义发布类型” UI插件创建自定义发布类型

Creating post type in CPT UI

You can also get custom taxonomy key by simply viewing the custom taxonomy in the admin area.

您还可以通过简单地在管理区域中查看自定义分类法来获取自定义分类法密钥。

Getting taxonomy key in WordPress

Use CPT UI plugin to create the same taxonomy on the target site where you want to import the taxonomy.

使用CPT UI插件在要导入分类法的目标站点上创建相同的分类法。

Create Taxonomy in CPT UI plugin

Repeat the process for all custom post types and taxonomies that you want to import.

对要导入的所有自定义帖子类型和分类重复此过程。

Bonus Tip: If you used the CPT UI plugin to create your post type, then you can also use it to migrate them. But this only works if the original custom post type was created using this plugin. Visit the Import / Export section in the plugin settings and follow onscreen instructions.

温馨提示:如果您使用CPT UI插件来创建帖子类型,则也可以使用它来迁移它们。 但这仅在使用此插件创建原始自定义帖子类型时有效。 访问插件设置中的“导入/导出”部分,然后按照屏幕上的说明进行操作。

插件创建的自定义帖子类型和分类法 (Custom Post Types & Taxonomies Created by Plugins)

Many popular WordPress plugins use custom post types and taxonomies to handle custom content types. For example, Soliloquy uses them to create sliders, eCommere plugins use them to create products, etc.

许多流行的WordPress插件使用自定义帖子类型和分类法来处理自定义内容类型。 例如, 独白使用它们来创建滑块,eCommere插件使用它们来创建产品等。

If you want to keep using those plugins, then you don’t need to import CPTs. Simply install the plugin on the target site, and you will have the custom post types and taxonomies ready on your site.

如果您想继续使用这些插件,则无需导入CPT。 只需将插件安装在目标站点上,即可在站点上准备好自定义帖子类型和分类法。

Many such plugins come with their own import/export features but if a plugin does not have that feature you can still export the data.

许多此类插件都具有自己的导入/导出功能,但是如果插件不具有该功能,您仍然可以导出数据。

在WordPress中导出/导入自定义帖子类型和分类法数据 (Exporting / Importing Custom Post Type and Taxonomies Data in WordPress)

WordPress comes with a powerful import/export tool which allows you to export and import WordPress data. Simply go to Tools » Export.

WordPress带有功能强大的导入/导出工具,可让您导出和导入WordPress数据。 只需转到工具»导出

Exporting custom post type in an XML file using WordPress built in export tool

You will see all your post types listed there. Select the post types you want to export and press the Download Export File button.

您将在此处看到所有帖子类型。 选择您要导出的帖子类型,然后按“下载导出文件”按钮。

WordPress will now prepare an XML export file and your browser will start downloading it.

WordPress现在将准备一个XML导出文件,您的浏览器将开始下载它。

Now switch to your target site where you want to import this data. Go to Tools » Import. You will see a number of options, click on WordPress.

现在切换到要在其中导入此数据的目标站点。 转到工具»导入 。 您将看到许多选项,单击WordPress。

WordPress import tool

This will bring up a popup asking you to install WordPress importer plugin. Click on the install button and then click on Activate Plugin & Run importer link.

这将弹出一个弹出窗口,要求您安装WordPress导入程序插件。 单击安装按钮,然后单击“ 激活插件并运行导入程序”链接。

Installing WordPress importer plugin

On the importer screen, you need to click on the choose file button and then select the XML file you downloaded earlier. Next, click on the upload file and export button.

在导入器屏幕上,您需要单击选择文件按钮,然后选择您先前下载的XML文件。 接下来,单击上载文件并导出按钮。

Importing WordPress using XML export file

WordPress will now import your custom post type data. All the custom post types you selected earlier will be imported. WordPress will also automatically add terms to the custom taxonomies.

WordPress现在将导入您的自定义帖子类型数据。 您之前选择的所有自定义帖子类型将被导入。 WordPress还将自动将术语添加到自定义分类法中。

That’s all, we hope this article helped you import and export custom post types and taxonomies in WordPress.

仅此而已,我们希望本文能帮助您导入和导出WordPress中的自定义帖子类型和分类法。

If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.

如果您喜欢这篇文章,请订阅我们的YouTube频道 WordPress视频教程。 您也可以在TwitterFacebook上找到我们。

翻译自: https://www.wpbeginner.com/wp-tutorials/how-to-exportimport-custom-post-types-in-wordpress/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值