REST API retrieving posts from www.sitename.comcategorynews instead of just just from www.sitename.com

I look a bit thorough some of the previously asked questions and stumbled upon wp-jsonwpv2pages?slug=news (and othe

I look a bit thorough some of the previously asked questions and stumbled upon /wp-json/wp/v2/pages/?slug=news (and other permutations) but it doesn't turn anything up. I'm kind of stuck on how to get posts for each category. I looked at /wp-json/wp/v2/ for trying to get a grasp on how routes work and looked at categories, but couldn't figure it out. I also checked out /wp/v2/posts?filter[category_name]=news but it just ends up being the same post no matter what I change the category name to.

I look a bit thorough some of the previously asked questions and stumbled upon /wp-json/wp/v2/pages/?slug=news (and other permutations) but it doesn't turn anything up. I'm kind of stuck on how to get posts for each category. I looked at /wp-json/wp/v2/ for trying to get a grasp on how routes work and looked at categories, but couldn't figure it out. I also checked out /wp/v2/posts?filter[category_name]=news but it just ends up being the same post no matter what I change the category name to.

Share Improve this question edited May 30, 2019 at 7:21 onibaku asked May 30, 2019 at 7:05 onibakuonibaku 32 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

If you want to retrieve posts, you need to use the posts endpoint for starters, not pages. So that's wp-json/wp/v2/posts. The documentation for that endpoint is here.

As you can see in the documentation, under List Posts, you can retrieve posts for a specific category using the categories argument. However, you need to use the category ID, not the slug.

http://example/wp-json/wp/v2/posts/?categories=14

If you absolutely must use the slug, then you need to retrieve that first, from the categories endpoint:

http://example/wp-json/wp/v2/categories/?slug=news

That will retrieve any categories with news as the slug. This response will include the category ID which you can store and use to query posts with that category.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745452101a4628317.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信