【发布时间】:2016-07-17 08:32:40
【问题描述】:
我创建了一个页面,显示来自 Wordpress 数据库的一些 json 格式的数据。现在我想显示帖子的类别ID,但它显示了对象"ads"之前的所有ID
我的来源:
<?php
header("Content-type: application/json");
include ('wp-load.php');
$loop = new WP_Query(array( 'post_status' => 'publish', 'post_type' => 'post'));
if($loop->have_posts()) : while($loop->have_posts()) : $loop->the_post();
$posts[] = array(
'id' => $post->ID,
'post_title' => $post->post_title,
'post_content' => $post->post_content,
'guid' => $post->guid,
'thumbnail' => (has_post_thumbnail() ? get_the_post_thumbnail_url() : ''),
'cats' => the_category_ID(),
);
endwhile; endif;
echo json_encode(array('ads' => $posts));
?>
【问题讨论】: