Trusted WordPress tutorials, when you need them most.
Beginner’s Guide to WordPress
WPBカップ
25 Million+
Websites using our plugins
16+
Years of WordPress experience
3000+
WordPress tutorials
by experts

WordPressでカスタム投稿タイプをインポート/エクスポートする方法

バックアッププラグインを使ってWordPressサイトを移動するのは簡単です。しかし、カスタム投稿タイプだけを移動したい場合は、独自のタクソノミーを持っていることが多いため、厄介なことになる可能性があります。

この投稿では、WordPressのカスタム投稿タイプのインポートとエクスポートについて説明します。また、投稿タイプにリンクされたカスタム・タクソノミーのインポートについても学びます。

主に2つのステップがあります。まず、カスタム投稿タイプとそのタクソノミーを移動します。2つ目のステップは、カスタム投稿タイプのデータをインポートすることです。

Migrate Custom Post Types

WordPressのカスタム投稿タイプとは?

WordPressのカスタム投稿タイプでは、通常の投稿やページとは異なる種類のコンテンツを作成することができます。カスタム投稿タイプを作成することで、様々なコンテンツを簡単に整理して表示することができます。

例えば、レビューサイトを運営している場合、「映画」、「本」、「テレビ番組」のカスタム投稿タイプがあるかもしれません。

さて、これらのカスタム投稿タイプをインポート、エクスポートする必要がある場合がある。

サイトを新しいホスティングサービスに移したり、複数のサイトを統合したりする場合にも便利です。また、誰かと設定を共有したり、同じ構造のWordPressサイトを複製する場合にも便利です。

しかし、カスタム投稿タイプの移動は厄介です。これらのタイプには、映画のジャンルや商品のカテゴリーなど、独自のカスタム・タクソノミーが付属していることがよくあります。これらのタクソノミーを正しく移動しないと、リンク切れや情報の消失につながります。

そのため、サイトを移転する際にカスタム投稿タイプの扱い方を知っておくと、多くの手間を省くことができる。

以下のセクションでは、WordPressでカスタム投稿タイプをインポート、エクスポートする方法を紹介します。ここでは、これから説明する方法をすべて簡単に紹介します:

関連記事カスタム投稿はすべて必要?WordPressでカスタム投稿タイプやタクソノミーが必要なのはどのような場合かについてのガイドをご覧ください。

準備はいいかい?始めよう

方法1:WordPressのカスタム投稿タイプとタクソノミーをエクスポートする(無料)

上級ユーザーは、テーマのfunctions.phpファイルやサイト固有のプラグインにコードを追加して、カスタム投稿タイプやタクソノミーを作成することを好むかもしれません。この方法では、コードをコピー&ペーストして新しいサイトに追加するだけです。

しかし、コードを見つけるのが難しい場合もある。

より簡単な方法は、新しいサイトで同じカスタム投稿タイプを作成することだ。投稿キーの値」を知っていればいいのです。

投稿キーの値は、WordPressデータベースが投稿タイプに使用する名前です。WordPressの管理エリアから投稿タイプにアクセスすることで見つけることができます。そして、投稿タイプのページにいるときに、設定やURLでその名前を探します。

Getting the post type key

投稿キーを入手したら、投稿タイプをインポートしたいサイトにアクセスします。その後、Custom Post Types UIプラグインを使ってカスタム投稿タイプを作成することができます。

それでは、カスタム投稿タイプUIをインストールして有効化しましょう。ヘルプが必要な場合は、WordPressプラグインのインストール方法のガイドを参照してください。

インストーラをインストールしたら、WordPressの管理エリアからCPT UI ” Add/Edit Post Typesに移動します。

次に、投稿キーの値を「投稿タイプスラグ」フィールドに入力し、その他のカスタム投稿タイプの詳細を入力します。CPTUIに移行しようとしているので、保存させてください。

投稿が完了したら、「投稿タイプを追加」ボタンをクリックしてください。

Creating pot type in CPT UI

ここで、古いWordPressサイトに戻り、「タクソノミーのキー値」を使ってカスタムタクソノミーをエクスポートしたい。

カスタムタクソノミーのキーは、投稿エディターでカスタムタクソノミーを表示する際にURLを見て見つけることができます。

Getting taxonomy key in WordPress

カスタムタクソノミーのキーをクリップボードにコピーし、新規サイトに戻るだけです。

管理エリアに入ったら、CPT UI ” Add/Edit Taxonomiesに移動して同じタクソノミーを作成します。

次に、タクソノミーのキーを’タクソノミースラッグ’フィールドに貼り付け、残りの項目を入力してください。タクソノミーを追加」ボタンをクリックし、進捗を保存することをお忘れなく。

Create Taxonomy in CPT UI plugin

これで、インポートしたいすべてのカスタム投稿タイプとタクソノミーについて、このプロセスを繰り返すことができます。

ボーナスヒント: CPT UIプラグインを使って投稿タイプを作成した場合、それを使って移行することもできます。しかし、これは元のカスタム投稿タイプがこのプラグインを使って作成された場合にのみ機能する。プラグイン設定の「Import / Export」セクションにアクセスして、画面の指示に従ってください。

方法2:プラグインで作成したカスタム投稿タイプとタクソノミー(推奨)

WordPressの人気プラグインの多くは、カスタム投稿タイプやタクソノミーを使ってカスタムコンテンツタイプを扱います。例えば、Soliloquyは スライダーを作成するためにそれらを使用し、eコマースプラグインは製品を作成するためにそれらを使用するなどです。

Soliloquy slider example

これらのプラグインを使い続けたいのであれば、CPTをインポートする必要はありません。ターゲットサイトにプラグインをインストールするだけで、カスタム投稿タイプとタクソノミーをサイトに準備することができる。

このようなプラグインの多くは、独自のインポート/エクスポート機能を持っているが、プラグインにその機能がなくても、データをエクスポートすることはできる。

方法3:WordPressでカスタム投稿タイプとタクソノミーのデータをエクスポート/インポートする(簡単)

WordPressには強力なインポート/エクスポート・ツールがあり、WordPressのデータをエクスポート/インポートすることができます。ツール ” エクスポート.

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

すると、すべての投稿タイプが表示されます。エクスポートしたい投稿タイプを選択し、「エクスポートファイルをダウンロード」ボタンを押してください。

WordPressがXMLエクスポートファイルを作成し、ブラウザーがすぐにダウンロードを開始します。

完了したら、このデータをインポートしたいターゲットサイトに切り替えることができます。

管理エリアからツール ” インポートに移動します。WordPress」セクションで、先に進み、「今すぐインストール」をクリックする。

WordPress import tool

インストーラをインストールすると、ボタンが「Run Importer」に変わります。それをクリックするだけで、インポーターの画面が表示されます。

ここで「Choose File」ボタンをクリックし、先ほどダウンロードしたXMLファイルを選択します。その後、「ファイルをアップロードしてインポート」ボタンをクリックします。

Importing WordPress using XML export file

WordPressがカスタム投稿タイプのデータをインポートします。先ほど選択したすべてのカスタム投稿タイプがインポートされます。

さらに、WordPressは自動的にカスタムタクソノミーにキーワードを追加します。

以上です!この投稿がWordPressのカスタム投稿タイプとタクソノミーのインポートとエクスポートのお役に立てれば幸いです。次の投稿では、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.

情報開示 私たちのコンテンツは読者支援型です。これは、あなたが私たちのリンクの一部をクリックした場合、私たちはコミッションを得ることができることを意味します。 WPBeginnerの資金源 をご覧ください。3$編集プロセスをご覧ください。

アバター

Editorial Staff at WPBeginner is a team of WordPress experts led by Syed Balkhi with over 16 years of experience in WordPress, Web Hosting, eCommerce, SEO, and Marketing. Started in 2009, WPBeginner is now the largest free WordPress resource site in the industry and is often referred to as the Wikipedia for WordPress.

究極のWordPressツールキット

ツールキットへの無料アクセス - すべてのプロフェッショナルが持つべきWordPress関連製品とリソースのコレクション!

Reader Interactions

24件のコメント返信を残す

  1. Syed Balkhi says

    Hey WPBeginner readers,
    Did you know you can win exciting prizes by commenting on WPBeginner?
    Every month, our top blog commenters will win HUGE rewards, including premium WordPress plugin licenses and cash prizes.
    You can get more details about the contest from here.
    Start sharing your thoughts below to stand a chance to win!

  2. Kerry says

    I am trying to export CPT data, but the WP export tool doesn’t list the CPT. I’m using the CPT UI plugin. Any help?

    • WPBeginner Support says

      For that specific plugin, you would want to check under CPT UI, Tools and you should see that plugin’s specific method for importing and exporting post types.

      管理者

  3. Bulut says

    There are people, Trouble Maker
    There are Bloggers, Trouble Eraser

    Thanks guys. You saved my day and time!

  4. Gabriela says

    Hi!

    We are switching themes – we want a new site basically – hopefully with a cleaner backend. The switch is from a custom-built theme to a new theme.
    Would it be best to install a new theme within our same back end, or would it be cleaner to export and import into a new backend?

  5. Raf says

    Clear incoherence between title and intent and practical advises:
    1) says “Exporting Custom Post Types and Taxonomies in WordPress”
    2) says “in some cases you may not be able to locate the code.”
    3) says “Don’t worry you can still create the same custom post type on the new site.”

    So if the post-type is created using the UI : you can not export it but only create it again. Why the article doesn’t clearly state it?

  6. Francis says

    So let say for instance if I was using a paid plugin that has to do with custom posts and want to switch to the free version how will i go about it? Am still very new to wordpress

  7. David says

    How can you export and have the option of exporting by month like you have when you export post and page?

  8. charles says

    When exporting custom post types it doesn’t export the featured image url path. Any idea how to resolve this?

    • Paul says

      I’m trying to do this too, which is why I landed here. I’m trying to rename a custom post type without losing the post data. Not having much luck.

    • Carlitos says

      It does not. you will want to bring that over either in your functions file or enter it in manually if you are using a plugin.

  9. Jim D says

    Is this something you would need to do if you are using a custom post type currently and wish to switch to a different theme?

    • WPBeginner Support says

      It depends on how you created the custom post types in the first place. If these custom post types were created by your old theme then you will need to export them before switching theme. If the custom post types were created using a plugin then they would remain unaffected when you switch the theme. Lastly, if you created the custom post type by adding code into your theme’s functions file then you just need to copy that code and paste it in your new theme.

      管理者

  10. Philip Downer says

    This article should have a bit of clarification. As Kris touched on, you can only import a custom post type if that specific custom post type actually exists on the destination site. You’ll need to either export and include the code that registers the post type; or if you’re using a plugin to handle custom post types, you’ll need to ensure that the same settings are used.

  11. Kris says

    Not to forget: themes also make their own custom post types (portfolio for example). Not only moving a site, but also switching themes can also be difficult

    I ended up coding the post type and taxonomies in a separate site-specific plugin with the aid of generatewp.com; I was surprised how easy it went and found it less confusing then CPT-UI

返信を残す

コメントありがとうございます。すべてのコメントは私たちのコメントポリシーに従ってモデレートされ、あなたのメールアドレスが公開されることはありませんのでご留意ください。名前欄にキーワードを使用しないでください。個人的で有意義な会話をしましょう。