Forums

[resolved] Can I create an RSS feed based on a content keyword (not categories or tags)? (3 posts)

  1. Maxormark
    Member
    Posted 3 years ago #

    I want to be able to provide an RSS feed based on a word that people may be interested in -- something similar to Google Alerts.

    I've checked over a few plug-ins including Extra Feed Links and Feed Wrangler but the most I seem to be able to do is produce an RSS feed based on a tag or category, which would mean a lot of extra work having to re-tag all my posts based on what people might wish to get by RSS some time in the future.

    Does anyone know of a specific plug-in which can do this, or how I can customize say Feed Wrangler to do this?

  2. Maxormark
    Member
    Posted 3 years ago #

    I now have a solution based on Feed Wrangler, although it's probably not very elegant.

    I duplicated wp-rss2.php as feed-news.php and added the code

    $keyword = $_GET['keyword'];
    $keyword_cap = ucwords($keyword);

    into the top of the file.

    Immediately after the <description> tag I added

    <?php echo $keyword_cap; ?>

    and after

    <?php while( have_posts()) : the_post(); ?>

    I added

    <?php if(strstr(strtolower(get_the_content()), $keyword )) : ?>

    closing the whole thing with

    <?php endif; ?>

    placed immediately before

    <?php endwhile; ?>

    Now, by using the feed http://www.mysite.co.uk/news/?keyword=keyword I get an RSS feed for whatever keyword I use providing, of course, that the keyword appears in the posts.

    One other thing; I upped the number of feed posts displayed in WordPress's settings to 200.

    Seems to work fine.

  3. scribu
    Member
    Posted 3 years ago #

    You should just use the search feed instead: http://example.com?s=keyword&feed=rss

Topic Closed

This topic has been closed to new replies.

About this Topic