$opts = array(); // any arguments
$query = WP_Query($opts);
Normally, we can get max_num_pages by using $totalPages = $query->max_num_pages;
But, i make json request by using this plugin http://wp-api.org/.
When i was trying to retrieve posts using the API, the response is just json object/array of posts. The problem is, $query->max_num_pages;
isn't accessible. I need that var to make a paginated request.
eg, i want to make a request:
$.ajax({
url: 'wp-json/posts?page=' + currentPage + '&filter[posts_per_page]=' + perPage + '&filter[cat]=' + category
});
How can we fill the currentPage
var if we don't know the max_num_pages ? if i just fill the currentPage
with 1
, it's ok (because assuming it was page 1). But how i know if there is page 2, page 3?
Do you have any idea? Thanks so much, for any help :)