1. Knowledge Base
  2. Posts Table Pro
  3. Developer documentation

Adding a custom column to the posts table

These instructions will explain how to add a custom column in Posts Table Pro. Custom columns are a good way to display data programmatically which is not available as one of the standard table columns.

Please note that this code is aimed at developers and if you don’t know how to use it then you should ask your developer. If you don’t have one, we recommend posting a job on Codeable. We have partnered with them to provide plugin customizations for our customers.

Or if you need a simpler method, then you could create a custom field, display this as a column and add the data to it for each post manually.

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

To add a custom column to your table you need to do the following:

  1. Add your column to the “columns” option used in the posts table. This can be via the plugin settings page, or directly in the shortcode using the columns option. The column can be called anything you like, e.g. sale_price, event_organiser, media_type, etc. It doesn’t matter what the name of the column is as long as you don’t use an existing column name already provided by the plugin.
  2. Create a new class which implements the Posts_Table_Data interface. This is the class that will retrieve the actual data for your custom column.
  3. Add a hook to your theme or custom plugin which creates and returns the data class created in Step 2.


For this example we’re going to assume the custom column we’re adding is called media_type.

1. Adding the column to the options or shortcode

In this example, we’re going to add the column directly in our shortcode. So our shortcode will be:

[posts_table columns="title,categories,media_type,cf:date_added"]

2. Creating the data class

Each column in the table has an associated object which implements the Posts_Table_Data interface. The interface has 3 functions, but the main one that you’ll be implementing is the get_data() function.

To simplify creating this class, your data class can extend Abstract_Posts_Table_Data. This provides base implementations for the other two functions which you probably won’t need.

Here’s an example of a data class for our media_type column:

if ( ! class_exists( 'Abstract_Posts_Table_Data' ) ) {

 * Gets data for the 'media_type' column to use in the posts table.
 * @license GPL-3.0
class Posts_Table_Data_Media_Type extends Abstract_Posts_Table_Data {

    public function get_data() {
        // Retrieve the media type from somewhere. In this example, we get it from the post meta table.
        $data = get_post_meta( $this->post->ID, 'media_type', true );

        // Return the media type and run through a filter.
	return apply_filters( 'posts_table_data_media_type', $data, $this->post );


You’ll notice in the above example, we run the returning data through a custom filter. You don’t have to do this, but the other columns in the table follow this convention, so it’s good practice.

3. Adding the data retrieval hook

The hook you need to add is posts_table_custom_table_data_<your_column>. So for this example we would register this hook:

add_filter( 'posts_table_custom_table_data_media_type', function( $data_obj, $post, $args ) { 
    return new Posts_Table_Data_Media_Type( $post ); 
}, 10, 3 );

This filter accepts 3 arguments: the data object to return (defaults to false), the current post object (WP_Post) and the table arguments object (Posts_Table_Args).

You could put the callback and the data class in the same file if you want, or keep them separate. Once you’ve added your callback and data object, you should now see your custom column in the table.

Changing the heading for the custom column

Posts Table Pro will give your column a heading based on its name. So in our example for media_type, the heading would be “Media Type”. If you want a different column heading, you can do this in the usual way by adding a : (colon) after the column followed by the heading. E.g:

[posts_table columns="title,categories,media_type:Type,cf:date_added"]
Still need help?
If searching the knowledge base hasn't answered your question, please contact support.

Related Articles