MUKI AI Summary
WordPress 預設的 RSS Feed 只能讀取 post type 為 post 的文章。若想讓 RSS Feed 讀取自訂文章類型,可在 functions.php 加入語法,顯示所有自訂文章類型。
若只希望顯示特定文章類型,需修改語法,設定 post type 為 post、course 和 movies。這樣即可在 RSS Feed 中讀取指定的自訂文章類型。...
如果你有使用 WordPress 的自訂文章類型 (custom post type),應該會發現預設的 RSS Feed 是讀不到該內容的,那是因為 WordPress 的 RSS,預設只會讀到「post type = post」的文章,也就是我們後台系統的「文章」。
讓 RSS Feed 讀到自訂文章類型
因此我們可以在 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'])) // 修改要放到 RSS Feed 的 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/