Skip to content
  • Why WPGetAPI?
  • Examples
  • Pricing
  • Plugins
    • PRO Plugin
    • API to Posts Plugin
    • OAuth 2.0 Plugin
  • Docs
  • Support
    • Frequently Asked Questions
    • Feature Request
    • Support Ticket
  • account_circle
PRO Plugin
Howdy! How can we help you?
  • Introduction

    • Quick Start
    • Frequently Asked Questions
    • Will this work with my API?
    • Understanding API docs
    • Step by Step Example
  • Setup

    • Setup Page
    • Endpoint Page
    • Parameters - Query String
    • Parameters - Headers
    • Parameters - Body POST
    • Shortcode
    • Template Tag
    • Gutenberg Block
  • Connecting your API

    • API Key in Headers
    • API Key in Query String
    • Authentication & Authorization
  • Output API Data

    • Format API to HTML
    • Format API to HTML Table
    • Format API to Image Gallery
    • Format JSON Data
  • Integrations

    • Send form data to API
    • WPForms to API
    • Gravity Forms to API
    • Contact Form 7 to API
    • WooCommerce to API
    • WooCommerce API Product Sync
    • wpDataTables to API
    • Connect WordPress to OpenAI
    • Connect RapidAPI to WordPress
    • Connect Zoho CRM to WordPress
    • Page Builders (Elementor, DIVI)
    • Formidable Forms to API
    • Elementor Form to API
    • JetFormBuilder to API
    • Fluent Forms to API
    • WS Form to API
    • Ninja Tables to API
    • Easy Digital Downloads(EDD) API Product Sync
    • Ultimate Member Forms to API
  • Tips & Tricks

    • Filters & Action Hooks
    • Code Snippets Plugin
    • Troubleshooting
    • Code Snippets
  • PRO Plugin

    • Installation
    • Actions
    • Tokens
    • Caching
    • Nested data
    • Chaining API calls
    • Dynamic Variables
    • Format API to HTML
    • Call API on user registration
    • Using AJAX to trigger API call
    • Base64 Encoding
    • Licensing
    • Filters & Action Hooks
  • OAuth 2.0 Plugin

    • Installation
    • How it works
    • Grant Type - Client Credentials
    • Grant Type - Authorization Code
    • Licensing
  • API to Posts Plugin

    • Installation
    • Getting Started
    • Multiple Endpoints
    • Mapping Fields
    • Filters & Action Hooks
    • Pagination

Our plugin support pagination by default. However, since there are various types of requests and responses for different API types, we have implemented filters to assist in identifying the exact parameters required for pagination to function correctly. You can add the necessary code snippets to your theme’s functions.php file, or utilize the Code Snippets plugin.


wpgetapi_pre_api_to_posts_pagination_next_value

This filter is used to find the exact pagination parameter from the API response and return the next value according to that.

function wpgetapi_pagination_next_value( $next, $data, $api_id, $endpoint_id ) {
	//Here we return next page number or URL for pagination
	return $next;
}
add_filter( 'wpgetapi_pre_api_to_posts_pagination_next_value', 'wpgetapi_pagination_next_value', 10, 4 );

Alternatively,

wpgetapi_api_to_posts_pagination_next_value

function wpgetapi_pagination_next_value( $next, $data, $api_id, $endpoint_id ) {
	//Here we return next page number or URL for pagination
	return $next;
}
add_filter( 'wpgetapi_api_to_posts_pagination_next_value', 'wpgetapi_pagination_next_value', 10, 4 );

wpgetapi_pre_api_to_posts_pagination_type

API pagination methods vary; sometimes the API provides a URL for the next page, while other times it offers the next page number directly. Additionally, the variable for the next page number may differ between APIs. To address these variations, a filter is utilized to define the type of pagination for the next page and specify what is passed to the query variable.

function wpgetapi_pagination_type( $type, $api_id, $endpoint_id ) {
	//Here we return $type based on previous code
	//If it is a page number then we return page number variable which we use in url
	//If it is a URL then we just return "url" string.
	return $type;
}
add_filter( 'wpgetapi_pre_api_to_posts_pagination_type', 'wpgetapi_pagination_type', 10, 3 );

Alternatively,

wpgetapi_pre_api_to_posts_pagination_type

function wpgetapi_pagination_type( $type, $api_id, $endpoint_id ) {
	//Here we return $type based on previous code
	//If it is a page number then we return page number variable which we use in url
	//If it is a URL then we just return "url" string.
	return $type;
}
add_filter( 'wpgetapi_api_to_posts_pagination_type', 'wpgetapi_pagination_type', 10, 3 );

API pagination methods vary; sometimes the API provides a URL for the next page, while other times it offers the next page number directly. Additionally, the variable for the next page number may differ between APIs. To address these variations, a filter is utilized to define the type of pagination for the next page and specify what is passed to the query variable.

  • For instance, when the API endpoint follows a structure like this: https://api.quotable.io/quotes?page=2 and requires the query variable page for pagination, there’s no need to add the filter because our plugin’s default query variable for pagination is page.
  • However, when dealing with an API structured like this: https://api.quotable.io/quotes?pageNumber=2 and needing to pass the query variable pageNumber (or other variables depending on the API) for pagination, it’s necessary to add the below filter code.

Example 1 – Response with page number

If we have data in API response like current page, next page, total pages, or total items and a pagination URL like this https://api.example.com/products?page_number=2

{
  "products": [
    {
      "id": 1,
      "name": "Product 1",
      "price": 19.99,
      "category": "Electronics"
    },
    {
      "id": 2,
      "name": "Product 2",
      "price": 29.99,
      "category": "Clothing"
    }
  ],
  "pagination": {
    "current_page": 1,
    "total_pages": 5,
  }
}

The below code will be used when there is pagination data like current page number and total pages in response. Here we have to change variables according to API Response

function wpgetapi_pagination_next_value( $next, $data, $api_id, $endpoint_id ) {
	//We have to pass all keys to reach page_number and total_pages like. $data['key1']['key2']
	if ( ( isset( $data['pagination']['current_page'] ) && isset( $data['pagination']['total_pages'] ) ) && $data['pagination']['current_page'] < $data['pagination']['total_pages'] ) {
		return $data['pagination']['current_page'] + 1;
	}
	return false;
}
add_filter( 'wpgetapi_pre_api_to_posts_pagination_next_value', 'wpgetapi_pagination_next_value', 10, 4 );

function wpgetapi_pagination_type( $wpgetapi, $type = 'page' ) {
	//Here we return only string with variable we need to pass in url
	//Default is 'page'
	return 'page_number';
}
add_filter( 'wpgetapi_pre_api_to_posts_pagination_type', 'wpgetapi_pagination_type', 10, 3 );

Example 2 – Response with next page URL

If we have data in response with the next page URL like below example

{
  "products": [
    {
      "id": 1,
      "name": "Product 1",
      "price": 19.99,
      "category": "Electronics"
    },
    {
      "id": 2,
      "name": "Product 2",
      "price": 29.99,
      "category": "Clothing"
    }
  ],
  "pagination": {
    "next_page_url": "https://api.example.com/products?page=2",
    "prev_page_url": null
  }
}

The code below will be used when pagination data is available with the next page URL. Here we have to change the variable according to API Response.

function wpgetapi_pagination_next_value( $next, $data, $api_id, $endpoint_id ) {
	//We have to pass all keys to reach Next url
	if ( isset( $data['pagination']['next_page_url'] ) && ! empty( $data['pagination']['next_page_url'] ) ) {
		return $data['pagination']['next_page_url'];
	}
	return false;
}
add_filter( 'wpgetapi_pre_api_to_posts_pagination_next_value', 'wpgetapi_pagination_next_value', 10, 4 );

function wpgetapi_pagination_type( $type, $api_id, $endpoint_id ) {
	  //When we receive a Next page url in the response, it’s necessary to add this filter and return just the 'url'.
       return 'url';
}
add_filter( 'wpgetapi_pre_api_to_posts_pagination_type', 'wpgetapi_pagination_type', 10, 3 );

Alternatively, can use the below filters

add_filter( 'wpgetapi_api_to_posts_pagination_next_value', 'wpgetapi_api_to_posts_pagination_next', 10, 4 );
add_filter( 'wpgetapi_api_to_posts_pagination_type', 'wpgetapi_api_to_posts_pagination_type', 10, 3 );
On this page
contact_support

Still not sure?

APIs can be daunting and sometimes downright confusing.

But we are here to help! Our support is amazing and we can assist you with any setup required and ensure your API integrations are a success!

Ask Us Anything

Connect your WordPress website to external APIs without writing a single line of code. Send data from WordPress to your API or display data from your API within WordPress.

Support

  • Documentation
  • Support Ticket
  • Refund Policy
  • Contact Us
  • About Us
  • Affiliates

Articles

  • Quick Start Guide
  • WooCommerce Orders to API
  • WooCommerce API Products Sync
  • Contact Form 7 to API
  • WPForms to API
  • Gravity Forms to API
  • WordPress to RapidAPI

WordPress API Plugins

  • Free WPGetAPI Plugin
  • PRO Plugin
  • API to Posts Plugin Plugin
  • OAuth 2.0 Authorization Plugin

© 2025 WPGetAPI. All Rights Reserved.

"*" indicates required fields

Name*
This field is for validation purposes and should be left unchanged.