1

I'm trying to do a custom query after an rss fetch_feed but for some reason nothing shows up. The code I'm using to fetch the feed is:

<?php // Get RSS Feed(s)
      include_once( ABSPATH . WPINC . '/feed.php' );

      // Get a SimplePie feed object from the specified feed source.
      $rss = fetch_feed( 'http://seko.se/feed.rss?rssId=97' );

      if ( ! is_wp_error( $rss ) ) : // Checks that the object is created correctly

          // Figure out how many total items there are, but limit it to 3. 
          $maxitems = $rss->get_item_quantity( 3 ); 

          // Build an array of all the items, starting with element 0 (first element).
          $rss_items = $rss->get_items( 0, $maxitems );

      endif;
    ?>

    <ul>
        <?php if ( $maxitems == 0 ) : ?>
            <li><?php _e( 'No items', 'my-text-domain' ); ?></li>
        <?php else : ?>
            <?php // Loop through each feed item and display each item as a hyperlink. ?>
            <?php foreach ( $rss_items as $item ) : ?>
                <li>
                    <a href="<?php echo esc_url( $item->get_permalink() ); ?>"
                        title="<?php printf( __( 'Posted %s', 'my-text-domain' ), $item->get_date('j F Y | g:i a') ); ?>">
                        <?php echo esc_html( $item->get_title() ); ?>
                    </a>
                    <div class="news-meta-rss">
                      <i class="fi-clock"></i><time datetime="<?php the_date('Y-m-d'); ?>"><?php the_time(get_option('date_format')); ?></time>
                    </div>
                </li>
            <?php endforeach; ?>
            <?php wp_reset_query(); ?>
        <?php endif; ?>
    </ul>

And the query I'm trying to do after this is:

<?php
  global $post;
  $args = array( 
    'numberposts' => 2,
    'post_type' => 'nyheter_cpt',
    'category__not_in' => array( 157, 150 ),
    );
  $myposts = get_posts( $args );
  foreach( $myposts as $post ) :  setup_postdata($post);
?>

  <div class="large-4 medium-6 small-12 columns">
    <div class="panel">
      <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
      <?php the_excerpt(); ?>
      <a href="<?php the_permalink(); ?>">Läs mer &raquo;</a>
      <ul class="news-meta">
        <li><i class="fi-clock"></i><time datetime="<?php the_date('Y-m-d'); ?>"><?php the_time(get_option('date_format')); ?></time></li>
        <li><i class="fi-torso-female"></i><div class="author"><?php the_author(); ?></div></li>
      </ul>         
    </div>
  </div>

  <?php endforeach; ?>
<?php wp_reset_query(); ?>

The query works just fine if I place it above the rss fetch_feed request, but as soon as I place it beneath it nothing shows up. Does anyone have a clue why?

  • I changed the query code to: – Josef Ulander Apr 2 '14 at 21:31
  • Instead of get_posts($args) use new WP_Query($args); and then add var_dump($myposts->request); just beneath it. What is the output? – s_ha_dum Apr 2 '14 at 21:57
  • Hey, I've done as you suggested and it returned "NULL". – Josef Ulander Apr 6 '14 at 17:48
  • NULL ? That doesn't makes sense. I don't know how to produce that result. – s_ha_dum Apr 6 '14 at 17:57
  • I don't think there is something wrong with the query itself since its working just fine if I place it above the RSS code. The thing is that I've copied the rss code from the codex so it should be correct. The problem remains even if I remove the header and footer so that no javascripts are loaded. There are no errors showing up in the console as well. I't a real mystery. – Josef Ulander Apr 6 '14 at 18:05
0

The error seems to be connected to the rss url itself, if I use 'http://seko.se/feed.rss?rssId=97' I can't create new loops beneath it but if I use another url such as 'http://www.wpbeginner.com/feed/' It works.

My original feed works just fine in other readers so I have no idea why it does not work in wordpress.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.