1. Knowledge Base
  2. Posts Table Pro
  3. Advanced Usage

Adding a ‘Date Modified’ column to the posts table

The Posts Table Pro WordPress table plugin lists your blog posts or any custom post type in a table. You can choose which columns to include, including a date column containing the date when the post was published. While it doesn’t come with a ‘Date modified’ column, we have provided a code snippet which will add a column containing the date when the post was last updated.

WordPress posts display modified date
A WordPress posts table with a custom 'Last Updated' column.

Please note that this code is aimed at developers and if you don’t know how to use it, then we recommend posting a job on Codeable. We have partnered with Codeable to provide customizations for our plugins.

Need professional assistance?
We've partnered with Codeable to provide our customers with expert help if required.

1. First, add modified_date to your list of columns

Once you have installed Posts Table Pro, you need to include modified_date in the list of columns.

For example, if you are setting the columns directly in the shortcode (instead of on the plugin settings page) then you might add:

[posts_table columns="title,categories,media_type,modified_date"]

The column header will say ‘Modified date’. You can easily change this using these instructions.

2. Use code snippet to add a custom column

Next, you need to use the following code snippet to create a custom column containing the post modified date:

/**
 * Gets data for the 'modified_date' column to use in the posts table.
 *
 * @license GPL-3.0
 */
if ( class_exists( 'Abstract_Posts_Table_Data' ) ) {
    class Posts_Table_Data_Modified_Date extends Abstract_Posts_Table_Data {
        //Get date_format value from the shortcode if it exists
        public function __construct( $post, $date_format = 'F j, Y' ) {
            parent::__construct( $post );
            $this->date_format = $date_format;
        }

        public function get_data() {
            // Retrieve the modified date.
            $data = get_the_modified_date($this->date_format, $this->post->ID);

            // Return the modified date and run through a filter.
            return apply_filters( 'posts_table_data_modified_date', $data, $this->post );
        }
    }

    add_filter( 'posts_table_custom_table_data_modified_date', function( $data_obj, $post, $args ) { 
        return new Posts_Table_Data_Modified_Date( $post, $args->date_format ); 
    }, 10, 3 );
}

This code snippet can be added to your theme’s functions.php file or you can add it to a custom plugin.

Again, if you don’t know how to use the code snippet then you should ask your developer or Codeable:

Need professional assistance?
We've partnered with Codeable to provide our customers with expert help if required.
Still need help?
If searching the knowledge base hasn't answered your question, please contact support.

Related Articles