A client needs an RSS feed for one custom post type - the feed works by default: hidden link
However, the author of these articles is not the WordPress author, but the author stored in a many-many relationship. Authors are stored in the 'people' custom post type and the 'Publication Author' post type stores the relationship.
To display in the front end a view shows the authors of each article: hidden link
Are you able to assist with the code to update the RSS feed - replacing the WordPress author of each article with the authors from the relationship? I assume this is possible by using a function to call an array and replace the field value of author in the RSS feed?
Thanks very much for this - it's working! Just two issues:
- the first was that our parent/child relationship is the other way around, so I swapped that around and it works
- but the list of authors needs to be separated by a comma. I have added this to the echo line, but it now has a comma on the last result also - is there a more elegant way to remove that comma from the last (or a single) result?
many thanks for your assistance - I'm fumbling around in the dark a bit with PHP unfortunately.
Ian
<?php
/**
* Template Name: Custom RSS Template - saiiawef
*/
$postCount = 10; // The number of posts to show in the feed
$postType = 'publication'; // post type to display in the feed
$posts = query_posts( array( 'post_type' => $postType, 'showposts' => $postCount ) );
header('Content-Type: '.feed_content_type('rss-http').'; charset='.get_option('blog_charset'), true);
echo '<?xml version="1.0" encoding="'.get_option('blog_charset').'"?'.'>';
?>
<rss version="2.0"
xmlns:content="hidden link"
xmlns:wfw="hidden link"
xmlns:dc="hidden link"
xmlns:atom="hidden link"
xmlns:sy="hidden link"
xmlns:slash="hidden link"
<?php do_action('rss2_ns'); ?>>
<channel>
<title><?php bloginfo_rss('name'); ?> - Feed</title>
<atom:link href="<?php self_link(); ?>" rel="self" type="application/rss+xml" />
<link><?php bloginfo_rss('url') ?></link>
<description><?php bloginfo_rss('description') ?></description>
<lastBuildDate><?php echo mysql2date('D, d M Y H:i:s +0000', get_lastpostmodified('GMT'), false); ?></lastBuildDate>
<language>en</language>
<sy:updatePeriod><?php echo apply_filters( 'rss_update_period', 'hourly' ); ?></sy:updatePeriod>
<sy:updateFrequency><?php echo apply_filters( 'rss_update_frequency', '1' ); ?></sy:updateFrequency>
<?php do_action('rss2_head'); ?>
<?php while(have_posts()) : the_post(); ?>
<item>
<title><?php the_title_rss(); ?></title>
<link><?php the_permalink_rss(); ?></link>
<pubDate><?php echo mysql2date('D, d M Y H:i:s +0000', get_post_time('Y-m-d H:i:s', true), false); ?></pubDate>
<dc:creator><?php $post_id = get_the_ID();
$relationship = 'person-analysis-opinion';
$connected_posts = toolset_get_related_posts(
$post_id,
$relationship,
array(
'query_by_role' => 'child', // starting from
'role_to_return' => 'parent',
'return' => 'post_object'
)
);