0

I'm trying to fetch some feeds using fetch_feed, however, into the for foreach, as the documentation says, I can access to values with common titles like title, permalink, etc using the get-> method, how can I access to those which looks like this:

 <SO:AppId>617422</SO:AppId>

Where those : generates error on my code. Any ideas?, the feed looks like this:

 channel
    title
    link
    image
      title
      url
    item
      SO:AppId
      SO:AppName
      SO:AppTime

I need to access those with the SO: into a foreach which using the get->SOMETHING method.

UPDATE******

This is my function:

 function get_external_feed($url, $number = 16) {
$rss = fetch_feed( $url );
if ( ! is_wp_error( $rss ) ) :
    $maxitems = $rss->get_item_quantity( number ); 
    $rss_items = $rss->get_items( 0, $maxitems );
    return $rss_items;
endif;

 }

and my foreach looks like this:

 <?php if (count($feeds) == 0 ) : ?>
 <h3>No upcomming dates so far, come back later for more!</h3>
 <?php else : ?>
 <?php foreach ( $feeds as $item ) : ?>
       <?php $item->get->title(); ?>
 <?php endforeach; ?>
 <?php endif; ?>
6
  • 1
    Post your code please. It will make this easier to test.
    – s_ha_dum
    May 11, 2014 at 19:28
  • Did you had a look at fetch_feed May 11, 2014 at 19:38
  • What is the "SO" namespace? Does it have a proper namespace definition at the beginning of the feed?
    – Otto
    May 11, 2014 at 20:03
  • mmm it says somthing like this <rss xmlns:SO="systemonesoftware.com/rss" version="2.0"> does it make sense??? May 11, 2014 at 20:10
  • xmlns: is "XML Namespace".
    – kaiser
    May 11, 2014 at 20:12

1 Answer 1

2

What is the "SO" namespace? Does it have a proper namespace definition at the beginning of the feed?

If it does, then you can use the get_item_tags function, most likely.

The fetch_feed() function returns a SimplePie object. See the documentation for SimplePie here:

http://simplepie.org/api/

Now, your $item in the code is a SimplePie_Item object:

http://simplepie.org/api/class-SimplePie_Item.html

Which has the get_item_tags function:

http://simplepie.org/api/class-SimplePie_Item.html#_get_item_tags

So, basically, the code would look like this:

$item->get_item_tags('http://example.com/namespace', 'AppId');

To get the SO:AppId. But in order for that to work, the "SO" namespace, which is not standard, has to be defined in the document somewhere, and the URI that it is defined as would be the URI you use in that function call.

The return from that call will be an array consisting of the attributes, data, and child elements. So you'll need to look through it to find the specific data you require.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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