【发布时间】:2012-09-07 15:36:23
【问题描述】:
我想从 WordPress DB 中获取数据,将它们推送到数组中并将数据传递给 JS。
除了将数据推入foreach ($posts as $post) 中的数组外,一切正常。
完整方法:
$array = array();
$category_name = "locations";
$args = array(
'numberposts' => -1,
'category_name' => $category_name
);
$posts = get_posts($args);
foreach ($posts as $post){
array_push( $array, array(
"title" => the_title($post->ID),
"cnt" => the_content($post->ID),
"id" => the_ID($post->ID),
"link" => the_permalink($post->ID)
));
}
当我做print_r($array) 时,我得到以下组合:
Post 39http://localhost:8080/testing/post-3/Post 27http://localhost:8080/testing/post-2/Post 15http://localhost:8080/testing/post-1/Array
(
[0] => Array
(
[title] =>
[cnt] =>
[id] =>
[link] =>
)
[1] => Array
(
[title] =>
[cnt] =>
[id] =>
[link] =>
)
[2] => Array
(
[title] =>
[cnt] =>
[id] =>
[link] =>
)
)
发生了什么事?为什么数据没有正确放入数组中?
任何建议都非常感谢。
【问题讨论】: