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

Displaying dates in Posts Table Pro

Posts Table Pro includes several shortcode options for how dates are displayed and formatted in your tables. For example, you can tell the plugin which columns are dates so that it will sort by date rather than alphabetically.

These options can only be controlled by adding them directly to the shortcode.

Date columns

The date_columns option is used to specify which columns in your table should be treated as dates. This is useful if you have custom fields or taxonomies which represent date values, and you want enable sorting for these columns or change the date format. This option should contain one or more columns (as a comma-separated list) using the same syntax as the columns option. For example:

[posts_table columns="image,title,cf:date,tax:custom_tax" date_columns="cf:date,tax:custom_tax"]

Setting this option will also allow you to set the date format for these columns using date_format option.

Should I use this for the date column or ACF date picker fields?

If you are using the built-in date column, or date picker fields created with Advanced Custom Fields, then you don't need to use the date_columns option. Posts Table Pro already knows these columns are dates and handles them appropriately.

The date_columns is only needed for additional date custom fields, for example:

  • You're using a standard WordPress custom field as a date
  • You're using an ACF text field as a date
  • You're using another custom fields plugin not supported by Posts Table Pro

Date sorting isn't working

If you're trying to sort by date custom field or taxonomy, you need to make sure you included the column in the date_columns option. For example, if you have a custom field called event_date, then your table shortcode might be:

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

If your column still isn't sorting correctly, it's probably because your dates are stored in European or Australian format in the WordPress database, i.e. day before month (d/m/y).

If this applies to your site, you will need to force the table to use EU/AU dates. The simplest way to do this is to install our helper plugin which forces all date custom fields and taxonomies in your table to be "day first" rather than "month first". You can download the helper plugin here:

Download the "Force EU/AU Dates" plugin for Posts Table Pro

Install this plugin by uploading the zip file in the usual way from your WordPress Dashboard.

You can also force dates to be in EU/AU format on a per-field or per-taxonomy basis, by adding some code to your theme. The relevant hooks are:

Date format

The date_format option tells the table how to format the date column in the table. It only works if your table includes a date column. If you don’t set this option, the default format in your WordPress settings will be used (see Date Format under the Settings → General menu).

You can set the date format to any valid date/time format string. For example: F j, Y will format the dates in this format: “August 24, 2016”. See the WordPress Codex for more information.

Example: [posts_table columns="title,date" date_format="F j, Y"]

The date format isn't working for my custom field

If the date format is wrong despite using the date_columns and date_format options in your shortcode, then the plugin where the date custom field is managed/stored is probably overriding the date format.

To fix this, go to the settings for your custom field and look for a date format option. You should probably remove the date_format option from your Posts Table Pro shortcode as this might cause conflicts with the date format in the 3rd party plugin.

If your custom field has been provided by an events plugin, you will need to check the date format settings for that plugin. For example, if you're using Posts Table Pro to display a date field in the Events Calendar plugin then you can find these settings at Events → Settings → Display.

Related Articles

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