Iām trying to find a way to include a list of posts of a category and its sub categories in my app. For example, this is the default behavior if you call /category/<parent_category> in a wp blog.
Using Frontity, I get a 404 not found if there are no posts in a specific category, even if it contains sub categories with posts (Frontity calls wp-json/wp/v2/categories?slug=... and then wp-json/wp/v2/posts?categories=<cat_id> where cat_id is the id of my parent category; the endpoint only returns the specific categoryās posts).
It would be possible, but Iām honestly more interested in a solution where I can implement the workflow:
Get id of parent category
Get sub categories
Fetch posts
ā¦ so that I donāt have to assign them to the parent category. Would I have to adapt wp-source and the handlers in that case?
Seems that I have to fetch categories?parent=<parent_cat> and then fetch per category.
Just so you know, WordPress 5.7 is going to include a new include_children option to retrieve the items of the children categories in the same request.
I meet similar problem. when I visit āhtttp://domain/category/top-category-nameā, it is ok. But when I visit āhtttp://domain/category/child-category-nameā, it return 404. There are posts in both category .
I feel Frontity is too yong , It need a long way to run.
I feel a little frustrated when I deep in Frontity, I even consider to turn off to gastby nowć
Did you try using the include_children param? If it didnāt work, could you please explain why?
By the way, in my opinion this has to do more with way the REST API works than with Frontity. It would be better solved in the API once than in the each framework (Gatsby, Next, Frontityā¦) multiple times.
I took the code above and adapted it to use the category (not parent_category) parameter. I might misunderstood the include_children parameter (tried several solutions with adding the parameter but in the end I got it working with the rest āfilterā). In any case I think this is more efficient than having multiple rest calls for this.
However, how I see @12732801 your issue, you try to access the child category directly? Whatās happening if you call the url directly for your blog?