Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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!

share|improve this question

1 Answer 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.)

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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