[英]Access a custom field from and RSS feed in WordPress
I am trying to access a custom field from an RSS feed in WordPress (using SimplePie), but I am not able to 我试图从WordPress中的RSS源访问自定义字段(使用SimplePie),但我无法
// get HCBC feed
$media_rss = fetch_feed('feed.theplatform.com/f/IfSiAC/VfW_gmOIG_yI');
if(!is_wp_error($media_rss)) {
// get limit of 5 items
$max_items = $media_rss->get_item_quantity(5);
// add items to indexed array starting at 0
$rss_items = $media_rss->get_items(0, $max_items);
}
foreach($rss_items as $item) {
$public_url = $item->get_item_tags('plmedia', 'publicUrl');
print_r($public_url);
}
you can see in the RSS that the namespace and tag are there, but for some reason $public_url is always empty. 您可以在RSS中看到命名空间和标记存在,但由于某种原因,$ public_url始终为空。 I'm not sure what I am doing wrong. 我不确定我做错了什么。
Turns out I didn't understand what the namespace was supposed to be. 结果我不明白命名空间应该是什么。 The following is correct: 以下是正确的:
foreach($rss_items as $item) {
$public_url = $item->get_item_tags('http://xml.theplatform.com/media/data/Media', 'publicUrl');
print_r($public_url);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.