简体   繁体   English

wordpress JSONAPI introspector总是将数字限制在10?

[英]wordpress JSONAPI introspector always limits number at 10?

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) 我对Wordpress和JSON API有点新意,请原谅我,如果这是一个新手问题,但我正在尝试获取一些不同的自定义帖子类型的所有帖子,并通过我自己的JSON控制器将它们作为JSON返回(扩展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. 我只获得“10”帖子,但数据库中有更多。 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. 我得到“74”,数据库中正确的帖子数量。 Essentially the JSON API is limiting the returned value to only 10 posts. 本质上,JSON API将返回值限制为仅10个帖子。 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. 我很确定我可以破解JSON API插件以允许更多,但这似乎会让我的代码搞砸任何API升级。

Is there a way to set the JSONAPI->introspector post number to "all" 有没有办法将JSONAPI-> introspector帖子编号设置为“all”

Thanks 谢谢

I'm answering my own question because it might be useful to someone else sometime. 我正在回答我自己的问题,因为它可能对其他人有用。

After reading through the somewhat sparse documentation on the wordpress plugin directory and getting nowhere. 阅读wordpress插件目录上有点稀疏的文档后无处可寻。 I found a variable in the JSON API code here's how it works PS -1 just mean "all": 我在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);

you can set the count to whatever you want before making the api call. 在进行api调用之前,您可以将计数设置为您想要的任何数量。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM