Hey there! How are you? I hope well!
Ok, here is the next thing I am searching for: how on Earth should I find out how many posts there are in the response I get which is already paginated at 10 posts every time?
WordPress did a fine job passing through the total number of posts and pages in the headers of the response! Just look out for this:
headers: { map: { allow: [ 'GET' ], 'x-wp-total': [ '45' ], 'x-wp-totalpages': [ '5' ], ... 'access-control-expose-headers': [ 'X-WP-Total, X-WP-TotalPages' ], link: [ '<http://geodoo.work/wp-json/wp/v2/posts?page=2>; rel="next"' ], ...
Nice and easy, huh? I have a total of 45 posts divided in 5 pages so far! Nice!
The only thing I have to do is find a way to pass those two variables over to the MainScreen component! The variables values are these (reading from the res parameter in the HTTP call):
res.headers.map['x-wp-total'][0] res.headers.map['x-wp-totalpages'][0]
After I find them I have to find the proper way to make the calls for the next pages of the posts!
NOTE: The official docs page is this where I first saw the two variables:
2 comments
Beberone
October 23, 2017 at 3:50 pm
Just realized that I haven’t read your blog for a while. Guess when you get closer you actually do lose some of the view huh?!
I thought if I subscribe your blog I’d get automatic notifications in my email but nothing came through. Something wrong with my settings?
gd
October 23, 2017 at 4:09 pm
Hey, you are right! I haven’t sent any newsletters lately, that’s why! Do not think that everything is so automatic around here, ok?
Hahahaha
Thanks for exposing all my vulnerabilities! 🙂