[ hide ]

    The syndicated_item_categories hook allows you to write filters which alter or act on the categories that a source feed provides for items to be syndicated by FeedWordPress. Feed categories are the terms provided by standard feed elements such as atom:category, rss:category, or dc:subject.

    The hook passes two parameters to any registered filter functions:

    1. $categories, an array containing the category names for each category assigned to an item by the syndication feed, and
    2. $post, an object of class SyndicatedPost representing the syndicated item as a whole.

    The return value for the filter function should be an array containing the names of categories to be assigned to the imported post in the WordPress database. The original array of category names should be returned unchanged if the filter will not modify the categories of the post.

    Data Format

    Feeds provide categories for posts using standard XML elements such as atom:category, rss:category or dc:subject. Each category is represented by a plain text name. The filter will receive an array whose elements contain each plain text name provided by the source feed. So, for example, an Atom feed with the following atom:entry on it:

    <name>Rad Geek</name>
    <title type="html"><![CDATA\[Get the Gun Out of the Room.]]></title>
    <link rel="alternate" type="text/html" href="" />
    <category scheme="" term="Fellow Workers" />
    <category scheme="" term="Politics" />
    <category scheme="" term="Power to the People" />
    <category scheme="" term="Smash the State" />
    <category scheme="" term="anarchy" />
    <category scheme="" term="Banking" />
    <category scheme="" term="Libertarians" />
    <category scheme="" term="Limited government" />
    <category scheme="" term="Minarchism" />
    <category scheme="" term="Money Monoply" />
    <category scheme="" term="Outreach" />
    <category scheme="" term="Regulation" />
    <category scheme="" term="Regulatory capture" />
    <category scheme="" term="Sheldon Richman" />
    <category scheme="" term="Shyla" />
    <category scheme="" term="State capitalism" />
    <summary type="html"><![CDATA\[...]]></summary>
    <content type="html"
    <link rel="replies" type="text/html" href="" thr:count="2"/>
    <link rel="replies" type="application/atom+xml" href="" thr:count="2"/>

    … a filter function hooked onto syndicated_item_categories will receive the following value in its first parameter ($categories):

    array("Fellow Workers", "Politics", "Power to the People",
      "Smash the State", "anarchy", "Banking", "Libertarians",
      "Limited government", "Minarchism", "Money Monoply",
      "Outreach", "Regulation", "Regulatory capture",
      "Sheldon Richman", "Shyla", "State capitalism")

    The return value from the filter function should be provided in the same format — i.e., as an array of strings, with each element the name of a category to assign to the syndicated item.


    add_filter('syndicated_item_categories', $callback, $order, /*arguments=*/ 2);
    // $callback should be the name of a callable function with two parameters, such as 'fwp_syndicated_item_categories_filter'
    // $order should be an integer value; a lower value means that the filter will be executed sooner; a higher value means later

    function fwp_syndicated_item_categories_filter ($categories, $post) { // A syndicated item with cats named A, B, and C // will get array('A', 'B', 'C') passed in the // $categories parameter

    /* ... */

    return $categories; }


    This example filter will filter incoming categories so that syndicated articles that the feed assigns to the category “Foo” will instead be treated as if they had been assigned to the category “Bar”.

    Plugin Name: FWP+: Recategorize "Foo" to "Bar"
    Plugin URI:
    Description: alters the categories of incoming syndicated posts to re-map category "Foo" to category "Bar."
    Version: 2010.1212
    Author: Charles Johnson
    Author URI:
    License: GPL
    • /

    add_filter( /*hook=*/ 'syndicated_item_categories', /*function=*/ 'fwp_filter_categories', /*order=*/ 10, /*arguments=*/ 2 );

    /** * fwp_filter_categories: Gets the categories provided * by the syndication feed and checks for any items * categorized as "Foo." If an item matches, instead of * appearing under category "Foo," it is re-assigned to * category "Bar." * * @param array $categories The category names assigned to the syndicated item. * @param SyndicatedPost $post An object representing the syndicated post. * The syndicated item data is contained in $post->item * The syndication feed channel data is contained in $post->feed * The subscription data is contained in $post->link * @return array The new categories to assign to the syndicated item. */ function fwp_filter_categories ($categories, $post) { $catsIn = $categories; // save values $categories = array(); // start from scratch

    foreach ($catsIn as $cat) : if (strtolower(trim($cat))=='foo') : $categories[1] = 'Bar'; else : // preserve $categories[2] = $cat; endif; endforeach;

    // Send it back return $categories; } /* fwp_filter_categories() */
    This page is a Wiki! Log in or register an account to edit.

    Leave a Reply

    Your email address will not be published. Required fields are marked *