3

I'm a little new to Wordpress and the JSON API so forgive me if this is a newbie question but i'm trying to get all of the posts of a few different custom post types and return them as JSON via my own JSON controller (extending the JSON API)

if I do this:

$posts = $json_api->introspector->get_posts(array('post_type' => array('post','tweet','gallery','video','music'), 'post_parent' => 0, 'order' => 'ASC', 'orderby' => 'date', 'numberposts' => 100000000000));
echo count($posts);

I only get "10" posts but there are a lot more in the db. Whereas if I do this:

echo count(get_posts(array('post_type' => array('post','tweet','gallery','video','music'), 'post_parent' => 0, 'order' => 'ASC', 'orderby' => 'date', 'numberposts' => 100000000000)));

I get "74", the correct number of posts in the db. Essentially the JSON API is limiting the returned value to only 10 posts. I'm pretty sure I can hack the JSON API plugin to allow more but that seems like it would mess up my code for any API upgrades.

Is there a way to set the JSONAPI->introspector post number to "all"

Thanks

4

1 回答 1

5

我正在回答我自己的问题,因为它有时可能对其他人有用。

在阅读了 wordpress 插件目录上有些稀疏的文档后,一无所获。我在 JSON API 代码中发现了一个变量,这是它的工作原理 PS -1 仅表示“全部”:

$json_api->query->count=-1;
$posts = $json_api->introspector->get_posts(array('post_type' => array('post','tweet','gallery','video','music'), 'post_parent' => 0, 'order' => 'ASC', 'orderby' => 'date', 'numberposts' => 4));
echo count($posts);

您可以在进行 api 调用之前将计数设置为您想要的任何值。

于 2012-05-24T00:11:25.363 回答