【发布时间】:2011-01-11 04:22:13
【问题描述】:
目前为止有这个
get_currentuserinfo(); $the_post = get_posts("author=" . $current_user->ID . "&posts_per_page=1"); $the_post = $the_post[0];
但我不确定如何从数组中获取 ID
【问题讨论】:
目前为止有这个
get_currentuserinfo(); $the_post = get_posts("author=" . $current_user->ID . "&posts_per_page=1"); $the_post = $the_post[0];
但我不确定如何从数组中获取 ID
【问题讨论】:
get_posts() 将返回按发布日期降序排列的帖子数组。因此,使用您发布的代码,数组 ([0]) 中的第一篇文章将是作者发布的最后一篇文章。如果你真的想要用户的第一篇文章,你可以将 order 参数添加到调用 (&order=ASC) 以覆盖默认值。
我认为 ID 的密钥只是“ID”,因此您可以使用 $the_post = $post[0]['ID'] 检索它。但我不得不承认我记不清了,文档也没有详细说明,它也可能是“post_id”。您可以执行以下操作:print_r($the_post) 来检查返回数组的键。
【讨论】:
你可以这样写查询-
$oldest_post_query = get_posts("post_type=post&numberposts=1&order=ASC");
$oldest_post_id = $oldest_post_query[0]->ID;
//print the post title
<h1><a href="'.get_permalink( $oldest_post_id ).'" rel="next">'.get_the_title( $oldest_post_id ).'</a></h1>';
【讨论】: