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 use lazy load, either enable it on the plugin settings page or add
lazy_load="true" to the Posts Table Pro shortcode.
How to disable lazy load
To deactivate lazy load, either disable it on the plugin settings page or add
lazy_load="false" to the Posts Table Pro shortcode.
Implications of using lazy load
Enabling lazy load means that all post fetching, searching, and sorting is handled by the server rather than in the browser. As a result, lazy loaded tables behave differently from non-lazy loaded tables:
- 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 works differently – instead of searching the contents of the table, the search box above the table looks in the post title and the full content of the post (regardless of whether these are present as columns in the table). The search box does not look in any other columns of the table, such as attributes, custom fields, taxonomies, etc. 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, or date. The
sort_byoption is also limited – please see the sort_by documentation for details.
- The search_on_click feature only works for tags, categories and taxonomies, but not authors. This means that users can’t click on an author to filter the table.
These differences are due to the way in which WordPress itself interacts with the database, and are unavoidable.