0
试图遍历一组类别并显示最新帖子的标题。访问数组/对象中的值?
$feed_sources = array('goose-creek','sleepy-creek','fobr');
foreach ($feed_sources as $feed) {
$args = array('category_name' => $feed, 'posts_per_page' => 1);
$show = get_posts($args);
print_r($show);
此代码返回
Array ([0] => WP_Post Object ([ID] => 79 [post_author] => 1 [post_date] => 2015-03-19 08:58:40 [post_date_gmt] => 2015-03-19 09:58:40 [post_content] =>
但我没有运气在$显示[0] [ 'POST_TITLE'],$秀[0] [POST_TITLE],或访问它$显示[0] - >'post_title'
此外,是否有一个简单的方法来获得此数组与基本主题功能,如the_title();内容();等等?
使用$ show [0] - > post_title – 2015-03-31 17:34:31
WP函数通常使用全局$ post变量。你可以设置它的价值,使他们工作。 – 2015-03-31 17:36:53
不返回任何内容:( – 2015-03-31 17:36:56