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

Displaying dates in Posts Table Pro

Posts Table Pro includes several 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.

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 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:my_date,tax:my_custom_tax" date_columns="cf:my_date,tax:my_custom_tax"]

You don’t need to include the date column here, as this is always treated as a date. This is just for additional date columns such as custom fields.

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

Date sorting isn’t working for custom fields

If you’re trying to sort by date custom field, you need to make sure you included the column in the date_columns option. For example, if your custom field is 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 you’re using dates in European or Australian format, i.e. day before month (d/m/Y), rather than in US format which is month before day (m/d/Y).

If this applies to your site, you will need to force the table to use European dates. The simplest way to do this is to install our helper plugin which forces all date custom fields 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 in the usual way from your WordPress Dashboard.

You can also force dates to be in EU format by adding some code to your theme or custom plugin. Please refer to the developer documentation for details.

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"]

Date format isn’t working for custom fields

If the date format is wrong despite using the date_columns and date_format options in your shortcode, then your custom field plugin is probably overriding the date format. To fix it, go to the settings for your custom field (e.g. in Advanced Custom Fields, or whichever custom field plugin you are using) and look for the date format option. Try setting the date format here so that it matches the setting in Posts Table Pro.

To get this working, you may need to remove the date_format option from your Posts Table Pro shortcode. This will prevent it from conflicting with the date format in the custom field plugin.

If your custom field has been provided by another type of plugin – for example a ‘date’ field in an events plugin – then 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.


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

Related Articles