0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

archiveページをACFの為に固定ページにする際に詰まった点

Posted at

WordPressを使用してarchiveページにAdvanced Custom Fields(ACF)で画像を管理画面から登録できるようにしようとした際、固定ページに変更する過程で詰まった点です。

踏んだ手順

・ファイル名をarchive-○○○.php→page-○○○.phpに変更
・管理画面から新しい固定ページを作成
・ACFで使用したい画像のカスタムフィールドを適用するページとして、新しく作成した固定ページを選択
・表側ページarchiveから固定ページに変更したページを開いても画面が真っ白になって開かなかった

原因

functions.phpで今回のカスタム投稿タイプの設定についての記述の中の
「has_archive => true」
によって固定ページで設定していたスラッグ名とバッティングしてしまい、ページが正常に表示されていなかったため。

functions.php
  register_post_type(
    'news',
    array(
      'label' => 'ニュース',
      'public' => true,
      'has_archive' => true,
      'show_in_rest' => true,
      'menu_position' => 5,
      'supports' => array(
        'title',
        'editor',
        'thumbnail',
        'revisions',
      ),
    )
  );

対策

「has_archive」をfalseにする、もしくは異なるスラッグを使用することで解決。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?