• Resolved kaviyaayyappan

    (@kaviyaayyappan)


    Hi,

    I have connected to the API and using shortcode I can pull the data in frontend. But API have 1000 posts and it shows 100 posts_per_page and total 10 pages.

    When i use query parameter I can get the corresponding page. But in frontend I want to show 10 posts_per_page and pagination to show the corresponding page results.

    I tried to add query parameter in shortcode and dynamic query to set the page number . But it is not working

    $current_page = isset($_GET[‘page’]) ? intval($_GET[‘page’]) : 1;

    $posts_per_page = 100;

    $response = do_shortcode(“[wpgetapi_endpoint api_id=’xxxxxxxxxxx’ endpoint_id=’xxxxx’ page='{$current_page}’ posts_per_page='{$posts_per_page}’ debug=’false’]”);

    / Check if the data contains the pagination details
    $total_pages = isset($data[‘total_pages’]) ? $data[‘total_pages’] : 1;

    / Display pagination links
    if ($total_pages > 1) {
    echo ‘

    // Previous page link
    if ($current_page > 1) {
    echo ‘<a href=”?page=’ . ($current_page – 1) . ‘”>&laquo; Previous</a>’;
    }

    // Page number links
    for ($i = 1; $i <= $total_pages; $i++) {
    if ($i == $current_page) {
    echo ‘<span class=”current-page”>’ . $i . ‘</span>’;
    } else {
    echo ‘<a href=”?page=’ . $i . ‘”>’ . $i . ‘</a>’;
    }
    }

    // Next page link
    if ($current_page < $total_pages) {
    echo ‘<a href=”?page=’ . ($current_page + 1) . ‘”>Next &raquo;</a>’;
    }

    Please guide me how to get the posts with pagination in the frontend.

    Thanks in advance,

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Support Damilare

    (@deabiodun)

    Hi!
    I see that the API returns 100 posts per page by default. What you are trying to achieve is best handled by the API provider.

    Can you check the documentation for the API you integrated whether it has a request parameter for controlling number of posts per page?

    You can also provide the link to the documentation so I can take a look for you.

    Regards.

    Plugin Support Ashok Desai

    (@adesaiudp)

    Closing this as we haven’t received a response. We’ll assume it has been resolved.

Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.