【发布时间】:2014-09-05 04:58:56
【问题描述】:
我正在 wordpress 中使用 wp_Query 尝试 JSON,但我收到错误 Fatal error: Cannot use object of type WP_Post as array。
这是我的代码
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<?php
require('wp-config.php');
//contoh parameter post per kategori >> category_name=kesehatan
//contoh parameter post per kategori >> showposts=5
$posts = array();
$the_query = new WP_Query( 'showposts=5' );
while ($the_query -> have_posts()) : $the_query -> the_post();
$thumb = wp_get_attachment_image_src(get_post_thumbnail_id(), 'thumbnail_name');
$post[thumbnail_post]= $thumb[0]; // Fatal error: Cannot use object of type WP_Post as array
$post[waktu_post]= get_the_time('Y-m-d H:i');// Fatal error: Cannot use object of type WP_Post as array
$post[link_detail_post]= the_permalink();// Fatal error: Cannot use object of type WP_Post as array
$post[judul_post]= title(); // Fatal error: Cannot use object of type WP_Post as array
$post[ringkasan_post]= the_excerpt(__('(more…)'));// Fatal error: Cannot use object of type WP_Post as array
$posts[] = $post;
endwhile;
echo json_encode(array('post'=>$posts));
?>
如何解决? 对不起我的英语
【问题讨论】: