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.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745452101a4628317.html
评论列表(0条)