I have a multisite install with one main site and 3 sub-sites together forming a network.
On the sub-site:
For a Custom Post Type called "Review" I have set up a couple of Custom Taxonomies. One of them is (author)"Rating" (a category-like taxonomy) and the 5 different terms are 1 star, 2 stars, 3 stars, 4 stars and 5 stars. These terms also have a description and for that description I use star images.
So far so good.
On the main site:
In the sidebar I want to show the 5 most recent Reviews of each of the 3 sub-sites. That's pretty easy by adding the feed of each of these 3 sub-sites into a widget. But what I so far have been unable to accomplish is to get the description of the terms of the Rating taxonomy to show up next to it.
For that I obviously first need to add the description of the terms of the custom taxonomy to the feed and then I need to extract it again from the feed.
Anyone that can help me with this, would be very much appreciated! If you need a better explanation, please let me know. I don't think having the url is necessary to solve this problem; if needed I can only give via private message.
Jurre Hanema answers:
To add the terms of a custom taxonomy to an RSS feed, try this:
$tax = 'product_cat';
$post_type = 'product';
if(get_post_type() != $post_type)
$categories = get_the_terms(get_the_ID(), $tax);
$the_list = '';
$cat_names = array();
foreach((array)$categories as $category)
$cat_names = sanitize_term_field('name', $category->name, $category->term_id, $tax, 'rss');
$cat_descriptions = sanitize_term_field('description', $category->description, $category->term_id, $tax, 'rss');
$cat_names = array_unique($cat_names);
$cat_descriptions = array_unique($cat_descriptions);
foreach($cat_names as $cat_name)
$the_list .= "\t\t<category domain=\"". $tax ."\"><![CDATA[" . @html_entity_decode($cat_name, ENT_COMPAT, get_option('blog_charset') ) . "]]></category>\n";
foreach($cat_descriptions as $cat_description)
$the_list .= "\t\t<wpq:category_description domain=\"". $tax ."\"><![CDATA[". @html_entity_decode($cat_description, ENT_COMPAT, get_option('blog_charset')) ."]]></wpq:category_description>\n";
As you can see in the function wpq_the_category_rss(), this function works for posts of type 'product' and for the taxonomy 'product_cat'. You can of course change these two to your liking.
The code adds a new element <wpq:category_description> containing the description of the term for each term the post is associated with. (I invented the wpq-namespace to keep the RSS valid and all).
Do you think this is enough or do you need more help with reading this data back from the feed? (if so, please post the code you are using now)
Your code sample works perfect and indeed adds the new element to the feed!
Yes, it would be really helpful if you can help with reading this data back from the feed too.
What I am using now to call the feed is a RSS widget (on the main site) where I use the feed-address of:
The output of the RSS now shows:
<?xml version="1.0" encoding="UTF-8"?>
<title>name of subsite » Reviews</title>
<atom:link href="http://sub-site.domain.com/reviews/feed/" rel="self" type="application/rss+xml" />
<description>description sub site</description>
<lastBuildDate>Thu, 27 Oct 2011 07:28:20 +0000</lastBuildDate>
<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
<pubDate>Mon, 12 Sep 2011 13:04:42 +0000</pubDate>
<category domain="rating"><![CDATA[4 stars]]></category>
<wpq:category_description domain="rating"><![CDATA[<img src="http://domain.com/wp-content/plugins/wp-postratings/images/stars(png)/rating_on.png" /><img src="http://domain.com/wp-content/plugins/wp-postratings/images/stars(png)/rating_on.png" /><img src="http://domain.com/wp-content/plugins/wp-postratings/images/stars(png)/rating_on.png" /><img src="http://domain.com/wp-content/plugins/wp-postratings/images/stars(png)/rating_on.png" /><img src="http://domain.com/wp-content/plugins/wp-postratings/images/stars(png)/rating_off.png" />]]></wpq:category_description>
<description><![CDATA[<p>If you enjoy poker at all this game is fun, quick and addicting.</p><p><a href="http://sub-site.domain.com/review/name-review/">title review</a> has originally been posted on <a href="http://sub-site.domain.com">name subsite</a></p>]]></description>
<content:encoded><![CDATA[<p>If you enjoy poker at all this game is fun, quick and addicting.</p><p><a href="http://sub-site.domain.com/review/name-review/">title review</a> has originally been posted on <a href="http://sub-site.domain.com">name sub site</a></p>]]></content:encoded>
Jurre Hanema comments:
It turns out that you can not modify the output of Wordpresses built-in RSS widget, therefore it was needed to create a new widget with my modifications. I put the code here: http://pastie.org/2774024
If you insert this code through your functions.php, you should end up with a new widget called "RSS (WPQ)". It works just the same as the default widget, except it also outputs the category name & description next to every item. I did not make this behaviour configurable, as that would require the copying and modification of even more code.
I don't know if this produces the exact output you want, but further modifications should be pretty easy. If you search for my comment "Modify final output here" you may even be able to figure it out for yourself.
Geweldig Jurre! Enorm bedankt! Werkt prima en makkelijk zelf aan te passen (heb de cat naam weggehaald)
Fantastic Jurre! Thanks so much! Works great en easy to adapt (deleted the cat name)