-1
내 WordPress 페이지에서 사용자 정의 json 피드를 만들려고합니다. 문제는 루프가 모든 객체를 덮어 쓰는 것처럼 보이므로 마지막 객체 만 json으로 인쇄합니다. 루프 내에서 메아리를 움직이려고했지만 브라우저에서 포맷되지 않은 것 같습니다. $data
의 선언은 매번 다시 초기화됩니다 값이 할당되어 의미의 foreach
내에서 무슨 일이 일어나고JSON은 배열의 마지막 객체 만 인쇄합니다.
foreach ($posts as $post) {
$r = str_replace("\n",'', shorten_txt($post->post_content, 500));
$n = str_replace("\r", '', $r);
$post_data = array(
'title' => get_the_title($post->ID),
'link' => get_permalink($post->ID),
'image' => catch_that_image(),
'content' => $n,
'time' => strtotime($post->post_date_gmt));
$data = (array('item' => $post_data));
}
echo json_encode($data);
감사합니다. 내가 할 수있을 때 받아 들일거야. – user3423384