admin管理员组文章数量:1432001
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.
1 Answer
Reset to default 0If 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.
本文标签: REST API retrieving posts from wwwsitenamecomcategorynews instead of just just from wwwsitenamecom
版权声明:本文标题:REST API retrieving posts from www.sitename.comcategorynews instead of just just from www.sitename.com 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745452100a2658933.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论