首先,我使用此代码将自定义帖子类型添加到我的提要中(如下所示):
function myfeed_request($qv) {
if (isset($qv[\'feed\']))
$qv[\'post_type\'] = get_post_types();
return $qv;
}
add_filter(\'request\', \'myfeed_request\');
后来,我遇到
WPBeginner\'s Adding Additional Text to Post Titles in RSS 并决定修改以下代码:
function wpbeginner_titlerss($content) {
global $wp_query;
$postid = $wp_query->post->ID;
$gpost = get_post_meta($postid, \'guest_post\', true);
$spost = get_post_meta($postid, \'sponsored_post\', true);
if($gpost !== \'\') {
$content = \'Guest Post: \'.$content;
}
elseif ($spost !== \'\'){
$content = \'Sponsored Post: \'.$content;
}
else {
$content = $content;
}
return $content;
}
add_filter(\'the_title_rss\', \'wpbeginner_titlerss\');
为了适应RSS中自定义帖子类型的显示:
function wpbeginner_titlerss($content) {
global $wp_query;
$post_type = $wp_query->post_type;
if( get_post_type() == \'essays\' ) {
$content = \'Essay: \'.$content;
}
elseif ( get_post_type() == \'gallery\' ){
$content = \'Gallery: \'.$content;
}
elseif ( get_post_type() == \'games\' ){
$content = \'Game: \'.$content;
}
else {
$content = $content;
}
return $content;
}
add_filter(\'the_title_rss\', \'wpbeginner_titlerss\');
最后的代码并没有以我想要的方式显示我的自定义帖子类型,任何想法/帮助都将不胜感激!