Wordpress 如何使用get_posts通过JSON发送title和permalink
这是我打印出来的Wordpress 如何使用get_posts通过JSON发送title和permalink,wordpress,Wordpress,这是我打印出来的 $args = array( 'category' => 'Animation', 'numberposts' => 8 ); $posts_array = get_posts( $args ); echo json_encode($posts_array); 结果如下:(有8个类似这样的相同JSON列表,为了方便起见只显示1个。) {“ID”:554,“发布作者”:“1”,“发布日期”:“2012-12-28 19:17:43”,“发布日期”:“2012-12-
$args = array(
'category' => 'Animation',
'numberposts' => 8
);
$posts_array = get_posts( $args );
echo json_encode($posts_array);
结果如下:(有8个类似这样的相同JSON列表,为了方便起见只显示1个。)
{“ID”:554,“发布作者”:“1”,“发布日期”:“2012-12-28 19:17:43”,“发布日期”:“2012-12-28 19:17:43”,“发布内容”:“太空竞赛正在进行。随着各国的竞争,我们跟踪一只被招募到太空计划中的黑猩猩的进展。他的结果可能会对全人类产生影响……他会接受挑战吗?”“博士后头衔”:“阿尔法”,“博士后摘录”:“博士后地位”:“发表”,“评论地位”:“公开”,“平”地位”:“公开”,“平”地位”:“公开”发布密码“:”发布名称“:”alpha“,”发送到“:”pinged“,”发布修改“:”2012-12-28 19:17:43“,”发布修改“:”2012-12-28 19:17:43“,”发布内容“:”过滤“,”发布父项“:”0,“guid:”http://localhost/Wordpress%203.4.2/?p=554,“菜单顺序”:0,“发布类型”:“发布”,“发布mime类型”:“评论计数”:“0”,“过滤器”:“原始”
但是我只想发送id和帖子内容。我不断得到空值,不知道为什么。只需按所需字段筛选:(
id和帖子内容
或title和permalink
)
$args = array(
'category' => 'Animation',
'numberposts' => 8
);
$posts_array = get_posts($args);
$send_array = array();
foreach ($posts_array as $key => $value)
{
$send_array[$key]["ID"] = $value->ID;
$send_array[$key]["post_content"] = $value->post_content;
}
echo json_encode($send_array);
exit;