1. Home
  2. Knowledge Base
  3. Posts Table Pro
  4. Posts Table Pro Shortcode Options
  5. Lazy load option for tables with many posts

Lazy load option for tables with many posts

The lazy load option in Posts Table Pro uses AJAX to speed up the posts table for sites with large numbers of posts.

What is lazy load?

By default, Posts Table Pro will load all of the data into the table when it is first displayed on screen. If you have more rows than can fit on a single page of results (e.g. you are showing 20 rows per page and you have 30 results) then it will create multiple pages with pagination links at the bottom of the table. However, all the posts on all the pages are loaded at the same time.

For large numbers of posts, this can cause a hit on performance as all matching posts need to be fetched from the database and then formatted by the table plugin. This can cause slower page load times and – for very large data sets – may even result in a server or database error when attempting to load the table.

If you’re worried about performance, then we recommend enabling the “lazy load” option. This will load the posts one page at a time via AJAX rather than all at once. As the user navigates between the pages of results, they will see a “Processing” message displayed (briefly) while the next posts are loaded from the database.

How to enable lazy load

To enable lazy load, add lazy_load="true" to the Posts Table Pro shortcode.

Example: [posts_table lazy_load="true"]

Limitations of lazy load

Enabling lazy load means that all post fetching, searching, and sorting is handled by the server rather than in the browser. This leads to some limitations with tables that use lazy load:

  • The filter dropdowns above the table will display all possible items (e.g. the ‘Categories’ filter will display all possible categories for all posts), regardless of the posts listed in the table. This means that some filter choices may not be applicable to certain posts in your table.
  • The search box is very restricted – it will only search within the title and content columns in your table (if present). It is not possible to search within other columns such as date, custom fields, taxonomies, etc. when using lazy load. If you want to search by other data then we recommend one of the following workarounds:
    • Add the extra data to the title or content fields so that it will be searchable in lazy load. Please note that the search box will still look in the title and content fields even if these aren’t columns in your table.
    • If you want people to be able to find posts by category, tag or custom taxonomy, then you can list these as filter dropdowns above the table instead of using the search box.
  • Table sorting is limited – you can only sort the table by ID, name, price, reviews or date. The sort_by option is also limited – please see the sort_by documentation for details.
  • The search_on_click feature is disabled, so users can’t click on a category or tag to filter the table.

These limitations are due to the way in which WordPress itself interacts with the database, and are unavoidable.

Was this article helpful?

Related Articles