1

我使用 Oauth2 与 woocommerse 连接。

但我不能使用过滤器,例如 /wp-json/wp/v2/post&filter[category_name]=food

我获得了有关用户的信息,例如http://my-site/wp-json/wp/v2/users,但是在页面上我获得了有关前 10 个用户的信息,我需要更多...当我使用过滤器时,例如:http://my-site/wp-json/wp/v2/users?filter[posts_per_page]=5-过滤器不起作用

我的代码:

require('vendor/autoload.php');
const CLIENT_ID     = 'my-ID';
const CLIENT_SECRET = 'my-secret';
const REDIRECT_URI           = 'http://wooc/test.php';
const AUTHORIZATION_ENDPOINT = 'http://my-site/oauth/authorize';
const TOKEN_ENDPOINT         = 'http://my-site/oauth/token';

$client = new OAuth2\Client(CLIENT_ID, CLIENT_SECRET);
if (!isset($_GET['code']))
{
 $auth_url = $client->getAuthenticationUrl(AUTHORIZATION_ENDPOINT, REDIRECT_URI);
header('Location: ' . $auth_url);
die('Redirect');
}
else
{
$params = array('code' => $_GET['code'], 'redirect_uri' => REDIRECT_URI);
$response = $client->getAccessToken(TOKEN_ENDPOINT, 'authorization_code',$params);
}
$client->setAccessToken("a6kpdxqqs3runou66ovzjjy54rvfubv64hhpdomn");
$data = $client->fetch("http://my-site/wp-json/wp/v2/users?filter[posts_per_page]=5");
echo "<pre>";
var_dump($data);

我不明白错误在哪里!请帮忙。谢谢你

4

2 回答 2

1

API 响应过滤功能已被更强大的查询参数(如 ?categories=、?slug= 和 ?per_page=)取代。

于 2017-11-12T22:11:51.427 回答
0

在 WordPress 4.7 中删除了任何帖子端点的过滤器参数,过滤器参数允许使用 WP_Query 公共查询变量过滤帖子。此插件恢复以前使用它的站点的过滤器参数:https ://github.com/luisfredgs/rest-filter

但是,您也可以将现有代码转换为 remove filter

类似这样的东西:

http://my-site/wp-json/wp/v2/users?filter[posts_per_page]=5

变成这样:

http://my-site/wp-json/wp/v2/users?posts_per_page=5
于 2017-02-05T00:39:05.217 回答