WordPress:如何在数组中包含自定义字段(SmplePie)

发布于 2024-08-03 20:50:05 字数 375 浏览 1 评论 0原文

Wordpress 2.8.4,Simple Pie Plugin 2.2.1

我有这个:

<?php echo SimplePieWP(
array(
   'http://gdata.youtube.com/feeds/base/videos?q=fifa10%20trailer&client=ytapi-youtube-search&alt=rss&v=2'
),
array(
   'items' => '1')
); ?>

而不是 fifa10 我想要一个带有键 name-of-game 的自定义字段的值在那里。

我该怎么做?

Wordpress 2.8.4, Simple Pie Plugin 2.2.1

I'm having this:

<?php echo SimplePieWP(
array(
   'http://gdata.youtube.com/feeds/base/videos?q=fifa10%20trailer&client=ytapi-youtube-search&alt=rss&v=2'
),
array(
   'items' => '1')
); ?>

Instead of fifa10 I'd like to have the value of a custom field with the key name-of-game in there.

How can I do this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

戴着白色围巾的女孩 2024-08-10 20:50:05

您可以使用 get_post_meta() 获取 WordPress 自定义字段的值:

get_post_meta($post->ID, 'name-of-game', true)

要将其包含在对 SimplePieWP 的函数调用中,请使用带有 .(点)的字符串连接:

<?php echo SimplePieWP(array('http://gdata.youtube.com/feeds/base/videos?q=' .
get_post_meta($post->ID, 'name-of-game', true) .
'%20trailer&client=ytapi-youtube-search&alt=rss&v=2'),array('items' => '1')); ?>

You get the value of a Wordpress custom field with get_post_meta():

get_post_meta($post->ID, 'name-of-game', true)

To include it in your function call to SimplePieWP, use string concatenation with . (dot):

<?php echo SimplePieWP(array('http://gdata.youtube.com/feeds/base/videos?q=' .
get_post_meta($post->ID, 'name-of-game', true) .
'%20trailer&client=ytapi-youtube-search&alt=rss&v=2'),array('items' => '1')); ?>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文