I'm trying JSON using wp_Query in wordpress, but i have get error Fatal error: Cannot use object of type WP_Post as array.
this my code
<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));
?>
how to fix it ? sorry for my english
Try renaming the $post variable. The GLOBAL $post variable might be being referenced that's why you get the error.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With