3
2

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 5 years have passed since last update.

WordPress: feedにカスタム投稿タイプを追加する【functions.php】

Posted at

★のとこにfeedに追加したいカスタム投稿タイプを追加する

functions.php
/**
 * feedにカスタム投稿タイプを追加する
 */
add_filter('pre_get_posts', 'add_custom_post_type_feed');

function add_custom_post_type_feed($query)
{
  if (is_feed())
  {
    $post_type = $query->get('post_type');
    if (empty($post_type))
    {
      $query->set('post_type', array('post', 'hoge1-posts', 'hoge2-posts', 'note-posts')); // ★
    }
    return $query;
  }
}
3
2
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
3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?