is_feed() 不适用于自定义 Post 类型

is_feed() not working for Custom Post Types

我有一个名为 quotes with ACF 的 CPT,我想将其添加到我的 RSS 提要中。

我的 rss url 是 example.com/feed/?post_type=quotes

当我使用 is_feed() 时,此代码有效。但是当我尝试将其限制为仅使用引号 CPT 时它不起作用:is_feed('quotes')

function add_fields_to_rss ($content) {  
    if(is_feed('quotes')) {
        $post_id = get_the_ID();
        $output = '<div><p>' . get_field('the_quote', $post_id) . '</p>';
        $output .= '<h3 style="text-align: right;">' . get_field('quoted', $post_id) . '</h3>';
        $output .= '</div>';
        $content = $content.$output;
    }
    return $content;
}
add_filter('the_content','add_fields_to_rss');

我还需要做些什么才能使此功能仅适用于我的报价 CPT 吗?

如果我了解到您当前想要将所有自定义帖子类型添加到 rss 提要? 如果是这样,以下应该有效:

add_filter( 'request', 'myfeed_request' );
function myfeed_request( $qv ) {
if ( isset( $qv['feed'] ) ) {
// gett all custom posts types 
$qv['post_type'] = get_post_types();
}
return $qv;
}

告诉我这是否是您要找的东西

编辑 1:回答您更新的问题和评论

以下用于将特定的海关帖子类型添加到 rss 提要

<?php add_filter( 'request', 'multiple_CPT_to_rss' );
function multiple_CPT_to_rss( $qv ) {
if ( isset( $qv['feed'] ) && !isset( $qv['post_type'] ) ) {
$qv['post_type'] = array( 'post', 'my_CPT_1', 'my_CPT_2' );
}
return $qv;
}; ?>

CPT 以 My rss url is example.com/feed/?post_type=my_post_type

的形式创建默认的 rss 链接

如果这似乎不适用于 is_feed('my_post_type')

我猜要让它正常工作,您需要使用 add_feed()

创建提要

但我没有测试,因为我走了另一条路。