Individual load of posts

Individual load of posts

toniojsttoniojst Posts: 6Questions: 2Answers: 0

Hello!

I would like to implement a datatable on my wordpress website, the situation is as follows:
- The number of posts is around 1500
- I would get the data via JSON url or via php file JSON
- I need pagination and search

The problem is that when I make a table with all the posts (1500) it loads the website for a very long time. Is it possible that depending on the change, the pagiantion page could also load, for example, the first 100 posts and then page 2 again the next 100 posts. But the search engine should work on all 1500 posts.

I searched for something on the internet and found the Pipeline option (https://datatables.net/examples/server_side/pipeline.html), but I don't know if this is what I'm looking for if it can be done at all.

KR. Toni

Answers

  • tangerinetangerine Posts: 3,365Questions: 39Answers: 395
    edited December 2020

    ...the first 100 posts and then page 2 again the next 100 posts.

    DT's server-side processing will do that.
    https://datatables.net/examples/data_sources/server_side.html

    However, I don't know why you would want WordPress posts in a table. Do you have an example of such usage?

    EDIT:....but what do I know about wordpress.....
    https://wordpress.org/plugins/posts-data-table/

  • toniojsttoniojst Posts: 6Questions: 2Answers: 0

    @tangerine thanks for answer. That i know where to start.

    I nee my post in table becuse i'm creating CMMS syst for me and i have a lot of equipment with a lot of data. And i need show this data in table.

    I review this page for server side but i cant find how to do the connection between pagination and loaded post. I want to dp when you at page1 it's load first 100 post o from 0-100 and when you click the page2 it's load post from 100-200...

    Where can i controll this?

  • tangerinetangerine Posts: 3,365Questions: 39Answers: 395

    You need to apply the lengthMenu option in your DT initialisation.
    https://datatables.net/reference/option/lengthMenu

  • toniojsttoniojst Posts: 6Questions: 2Answers: 0
    edited December 2020

    @tangerine i tkink that you dont realy understand what i want to do. I want to split source to multiple page and connect with pagination of table. So for example:

    PAGINATION________SOURCE
    Page 1_____________********/wp-json/wp/v2/posts/?page=1
    Page 2_____________********/wp-json/wp/v2/posts/?page=2
    Page 3_____________********/wp-json/wp/v2/posts/?page=3
    Page 4_____________********/wp-json/wp/v2/posts/?page=4
    ....

    So i need like this.

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    For that number of records, the table should load fast. This section of the FAQ should help, it discusses various techniques to improve performance,

    Cheers,

    Colin

  • toniojsttoniojst Posts: 6Questions: 2Answers: 0

    Problem is that my custom end point for whole 1500 post is slow. for now that my site create JSON REST endpoint for all 500 post it's need 10second. so i am thinkih if i can split this to multiple page?

  • kthorngrenkthorngren Posts: 21,342Questions: 26Answers: 4,954

    The Datatables way of paging is to use Server Side Processing. The protocol is described here. If you are unable to create a server script to follow that protocol then you can create your own system. You can use ajax.data as a function to pass the paging parameters to the server. Or you can use ajax.url().load() to change the url.

    Kevin

This discussion has been closed.