1. Home
  2. Knowledge Base
  3. Posts Table Pro
  4. Posts Table Pro Options

Posts table sort options

In Posts Table Pro, you can sort the posts when the table first loads. The table is "pre-sorted" when it is first displayed to the user.

Your users can also sort by clicking on a column heading. For example, clicking on the Title column will sort the posts alphabetically by title (A->Z). Clicking a column heading a second time will sort the column in the other direction (Z->A).

Sort on table load

You can easily choose how to sort your posts using the Sort posts by option in the table builder. It defaults to Date published.

The options are:

  • ID – sort by post ID
  • Title – sort by post title
  • Default WordPress order – sort by 'Page' order (Order field in the Edit Page Attributes box). Any post type with distinct menu_order values can be sorted with this option
  • Date published – sort by publish date of the post/page
  • Date modified – sort by last modified date
  • Author – sort by author name
Table generator sort options

Using the shortcode

You can also set the sort options in the [posts_table] or [posts_table_template] shortcode. Use the sort_by option with one of the following values:

  • id – sort by post ID
  • title – sort by post title
  • menu_order – sort by 'Page' order (Order field in the Edit Page Attributes box). Any post type with distinct menu_order values can be sorted with this option
  • date – sort by publish date of the post/page
  • name – sort by post ‘slug’
  • modified – sort by last modified date
  • author – sort by author name
  • comment_count – sort by number of comments
  • rand – random order

Examples

Sort by ID: [posts_table sort_by="id"]

Sort by last modified date: [posts_table sort_by="modified"]

Lazy load vs. standard load

For standard loading (i.e. when lazy load is disabled) you can also sort by any column present in the table. For example, if you have the Content column in your table you can use this column in the sort_by option:

[posts_table columns="title,content,date,author" sort_by="content" lazy_load="false"]

For lazy loaded tables, you can only sort by the keywords listed above. This is because the sorting is handled by the server when the products are retrieved from the database.

Sort by custom field

To sort by custom field, the field must be present in the table and lazy load must be disabled. Here's an example using the custom field engine_size:

[posts_table columns="title,content,cf:engine_size" sort_by="cf:engine_size" lazy_load="false"]

Date custom fields

To sort by date custom field, the same restrictions apply. In addition, you must register the custom field as a date column using the date_columns option:

[posts_table columns="title,content,cf:event_date" sort_by="cf:event_date" date_columns="cf:event_date" lazy_load="false"]

Sort order

This controls the direction to use for sorting by when the table is first displayed. By default, descending order is used for date-based sorting, and ascending is used for everything else.

You can set the sort order by selecting 'Ascending' or 'Descending' in the table builder, or directly in a shortcode by using the sort_by option with either asc or des. For example:

[posts_table columns="title,content" sort_by="date" sort_order="asc"]

Can I sort by multiple columns?

No, this is not currently possible. The table can only be sorted by a single column.

Can I sort the table by number?

If you’re using custom fields or taxonomies to store numbers instead of text, then you may wish to sort the table in number order. The only way to sort by number is to create a "Number" custom field using the plugin Advanced Custom Fields and disable lazy load.

Otherwise, the table is sorted alphabetically rather than numerically. This applies to all text-based columns including custom fields and taxonomies.

The only other way to enable the table to be sorted numerically number is to add the numbers in a format that will make sense when ordered alphabetically. For example:

  • If you add numbers in the format 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 and 11, then they will be sorted in the following order – 1, 10, 11, 2, 3, 4, etc. This does not look correct.
  • If you’re sorting by a custom field containing numbers 01, 02, 03, 04, 05, 06, 07, 08, 09, 10 and 11, then they will be sorted correctly both alphabetically and numerically.

Related Articles

If searching the knowledge base hasn't answered your question, please contact support.