Displaying dates in Posts Table Pro
Posts Table Pro lets you control how dates are displayed and formatted in your tables. For example, you can indicate which columns are dates so that it will sort by date rather than alphabetically.
Date columns
When you create columns in the Posts Table Pro table builder, you can open the Advanced settings and use the 'Column type' dropdown to indicate that the column is being used for 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.
Setting this option will also allow you to set the date format for these columns using date_format shortcode 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 set it as a date column. This is because Posts Table Pro already knows these columns are dates and handles them appropriately.
This 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 have set a column as a date column and it isn't sorting correctly by date, then 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
shortcode 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.