admin管理员组文章数量:1291217
I want to display the list of posts from my wordpress blog on someother site along with the author name, title, date and description. Hence, I decided to use WP REST API V2. As per WP REST API Documentation I retrived the data in JSON format by following example URL . I get all the information except author name.
Here is the partial JSON
.........
........
"_embedded": {
"author": [
{
"code": "rest_user_invalid_id",
"message": "Invalid user ID.",
"data": {
"status": 404
}
}
],
........
........
I also get same error if I try to visit the following link . I don't understand why this error occur even though the user exist. Does it deal with authentication?
Note: I had earlier modified a field in the WP database so that the actual user name is not displayed in urls and posts. However, I think this must not affect the JSON output because an another alias for user name is already present and displayed in my blog. Also, the same entries of my blog is displayed on another wordpress blog by a wordpress plugin which also shows the author name.
Please help me I am stuck and unable to find solution.
I want to display the list of posts from my wordpress blog on someother site along with the author name, title, date and description. Hence, I decided to use WP REST API V2. As per WP REST API Documentation I retrived the data in JSON format by following example URL http://example/wp-json/wp/v2/posts?_embed
. I get all the information except author name.
Here is the partial JSON
.........
........
"_embedded": {
"author": [
{
"code": "rest_user_invalid_id",
"message": "Invalid user ID.",
"data": {
"status": 404
}
}
],
........
........
I also get same error if I try to visit the following link http://example/wp-json/wp/v2/users/1
. I don't understand why this error occur even though the user exist. Does it deal with authentication?
Note: I had earlier modified a field in the WP database so that the actual user name is not displayed in urls and posts. However, I think this must not affect the JSON output because an another alias for user name is already present and displayed in my blog. Also, the same entries of my blog is displayed on another wordpress blog by a wordpress plugin which also shows the author name.
Please help me I am stuck and unable to find solution.
Share Improve this question asked Mar 25, 2017 at 4:12 geeksalgeeksal 1531 silver badge5 bronze badges 2- Im currently having this same issue, only after moving to production. – erwstout Commented Apr 6, 2017 at 22:44
- Are you using the wordfence plugin? @geeksal – erwstout Commented Apr 7, 2017 at 0:11
3 Answers
Reset to default 9Wordfence blocks the User endpoint from the public. In settings there is a checkbox you can unselect to make it visible in the WP Rest API again.
I know this is solved for op but for other users that come along from Google this is what I had to do:
- Go to WordFence "all options" page
- Search "rest" in the filter
- Uncheck the option "Prevent discovery of usernames through '/?author=N' scans, the oEmbed API, and the WordPress REST API"
- Go to LiteSpeed Cache and choose Purge All
You might be using different plugins for security and caching but the general idea remains:
- Make sure your security plugin isn't blocking access
- Clear your cache
If the user data is indeed being blocked by Wordfence (or another security plugin), and you want to continue to utilize that security feature, you can modify the REST API's response, and add in just the fields that you want to use (which would presumably reveal less data than what is exposed by the standard API call). This documentation explains about modifying API responses: https://developer.wordpress/rest-api/extending-the-rest-api/modifying-responses/. Gives you an additional option.
本文标签: phpWP API V2 returning Invalid User ID
版权声明:本文标题:php - WP API V2 returning Invalid User ID 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741524860a2383405.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论