Properly loop through and paginate page on each function call

Instead of fetching the first page, then looping over the total pages count from a variable, instead store it as an option, and use a second value to specify next page.

This way, you retrieve the next page number, fetch it, process the posts, then update the total pages options using the newer header from that request, and add 1 to the next page option and save it. If next page is larger than total pages reset it to 1.