1

First, I have used this code to add my custom post types into my feed (below):

function myfeed_request($qv) {
    if (isset($qv['feed']))
        $qv['post_type'] = get_post_types();
    return $qv;
}
add_filter('request', 'myfeed_request');

Later, I encountered WPBeginner's Adding Additional Text to Post Titles in RSS and decided to modify the following code:

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');

Into this to suit the display of my custom post types in 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');

This final code does not display my custom post types the way I want at all, any idea/help will be greatly appreciated!

1

Since you're defining $post_type, why not just use it instead?

function wpbeginner_titlerss($content) {
    global $wp_query;
    $post_type = $wp_query->post_type;

    if( $post_type == 'essays' ) {
        $content = 'Essay: '.$content;
    }
    elseif ( $post_type == 'gallery' ){
        $content = 'Gallery: '.$content;
    }
    elseif ( $post_type == 'games' ){
        $content = 'Game: '.$content;
    }
    else {
        $content = $content;
    }
    return $content;
}
add_filter( 'the_title_rss', 'wpbeginner_titlerss' );

(This assumes you have created custom post types, essays, gallery, and games.)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.