WP REST API v2无法使用过滤器
问题描述:
I使用Oauth2与woocommerse连接。WP REST API v2无法使用过滤器
但我不能使用过滤器,例如/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);
我不明白的地方的错误! 请帮忙。谢谢
答
在WordPress 4.7中,删除了任何后端点的过滤参数,过滤参数允许使用WP_Query公共查询变量过滤该过滤参数。此插件为以前使用它的站点恢复过滤器参数:https://github.com/luisfredgs/rest-filter
但是,您也可以将现有代码转换为删除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
答
的API响应过滤功能已被取代由更强大的查询参数,如类别=,蛞蝓=和?per_page =。