0
我使用下面的代碼在Wordpress中獲取帖子信息。我在網上找到了這個代碼,並添加了兩個變量「date」和「author」。但是,這些目前沒有按要求/預期工作。在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);
}
這很好,非常感謝您的幫助! –
歡迎我的開發者朋友! – ScyGeek