如果你有使用 WordPress 的自訂文章類型 (custom post type),應該會發現預設的 RSS Feed 是讀不到該內容的,那是因為 WordPress 的 RSS,預設只會讀到「post type = post」的文章,也就是我們後台系統的「文章」。
因此我們可以在 functions.php 加入一些語法,就可以讓 RSS Feed 讀到自訂文章類型:
<?php function myfeed_request($qv) { if (isset($qv['feed'])) $qv['post_type'] = get_post_types(); return $qv; } add_filter('request', 'myfeed_request'); ?>
以上這段語法會顯示所有的自訂文章類型。
但如果你不希望顯示所有文章類型的話,只要將語法稍作修改即可:
<?php function myfeed_request($qv) { if (isset($qv['feed']) && !isset($qv['post_type'])) $qv['post_type'] = array('post', 'course', 'movies'); return $qv; } add_filter('request', 'myfeed_request'); ?>
How to Add Custom Post Types to Your Main WordPress RSS Feed
Learn how you can add Custom Post Types to your main WordPress RSS feeds by including or excluding specific custom post types.
https://www.wpbeginner.com/wp-tutorials/how-to-add-custom-post-types-to-your-main-wordpress-rss-feed/