【发布时间】:2017-04-12 22:54:45
【问题描述】:
我正在使用以下代码在 Wordpress 中获取帖子信息。我在网上找到了这段代码,并添加了两个变量“日期”和“作者”。但是,这些目前没有按要求/预期工作。
对于“日期”,它返回完整的日期/时间戳(即 2017-03-08 15:12:39),而不是使用 get_the_date() 时检索到的格式良好的日期; (即 2017 年 3 月 8 日)。我可以调整我的标记来格式化日期吗?
对于“作者”,什么都没有返回?
提前致谢。
$postData = get_posts($postParameters);
$posts = array();
foreach($postData as $post) {
$post = array(
"id" => $post->ID,
"title" => $post->post_title,
"excerpt" => $post->post_excerpt,
"date" => $post->post_date,
"author" => $post->post_author,
"slug" => $post->slug,
"image" => array("url" => get_the_post_thumbnail_url($post->ID)),
"link" => get_permalink($post->ID),
"category" => get_the_category($post->ID)[0]->name
);
array_push($posts, $post);
}
【问题讨论】: