WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] [Plugin: FreshPost] Dynamic Queries for RSS (2 posts)

  1. jongos
    Member
    Posted 5 years ago #

    I'm using this plug-in as part of a larger project. One thing I'm stuck on is how to dynamically aggregate persistent search results from sites like Icerocket and Yahoo (they offer RSS for search) for each entry. Here's what works:

    <h3 class="site-subtitle"><?php echo get_post_meta($post->ID, "Company", true); ?> Aggregator</h3>
    
    <?php // Get RSS Feed(s)
    include_once(ABSPATH . WPINC . '/rss.php');
    $rss = fetch_rss('http://www.icerocket.com/search?tab=web&q=companyname&rss=1');
    $maxitems = 10;
    $items = array_slice($rss->items, 0, $maxitems);
    ?>
    
    <?php foreach ( $items as $item ) : ?>
    <ul>
    <li><a href='<?php echo $item['link']; ?>' title='<?php echo $item['description']; ?>'>
    <?php echo $item['title']; ?>
    </a></li>
    </ul>

    and here's what doesn't work:

    <h3 class="site-subtitle"><?php echo get_post_meta($post->ID, "Organization", true); ?> Aggregator</h3>
    
    <?php // Get RSS Feed(s)
    include_once(ABSPATH . WPINC . '/rss.php');
    $rss = fetch_rss('http://www.icerocket.com/search?tab=web&q=<?php echo get_post_meta($post->ID, "Company", true); ?>&rss=1');
    $maxitems = 10;
    $items = array_slice($rss->items, 0, $maxitems);
    ?>
    
    <?php foreach ( $items as $item ) : ?>
    <ul>
    <li><a href='<?php echo $item['link']; ?>' title='<?php echo $item['description']; ?>'>
    <?php echo $item['title']; ?>
    </a></li>
    </ul>

    As you can see, I'm trying to substitute a normal search query company with this string that calls data from Freshpost <?php echo get_post_meta($post->ID, "Company", true); ?> but it doesn't work. It just breaks the code. Any ideas as to how I can call a dynamic query so that the company name is searched and returned as an RSS feed?

  2. jongos
    Member
    Posted 5 years ago #

    Nevermind, the solution is:

    <?php 
    
    $org = get_post_meta($post->ID, "Organization", true);
    print $org;
    
    ?> Aggregator</h3>
    
    <?php // Get RSS Feed(s)
    if ($org) {
    include_once(ABSPATH . WPINC . '/rss.php');
    $url = 'http://www.icerocket.com/search?tab=web&q='. urlencode($org) . '&rss=1';
    // print $url;
    $rss = fetch_rss($url);
    $maxitems = 10;
    $items = array_slice($rss->items, 0, $maxitems);
    ?>
    <?php foreach ( $items as $item ) : ?>
    <ul>
    <li><a href='<?php echo $item['link']; ?>' title='<?php echo $item['description']; ?>'>
    <?php echo $item['title']; ?>
    </a></li>
    </ul>

    Basically, you need to assign the company name to a variable which is then printed as part of the URL.

Topic Closed

This topic has been closed to new replies.

About this Topic