DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Related

  • Advanced Maintenance of a Multi-Database Citus Cluster With Flyway
  • Why Database Migrations Take Months and How to Speed Them Up
  • Unmasking Entity-Based Data Masking: Best Practices 2025
  • Fixing Common Oracle Database Problems

Trending

  • System Coexistence: Bridging Legacy and Modern Architecture
  • Optimizing Integration Workflows With Spark Structured Streaming and Cloud Services
  • Can You Run a MariaDB Cluster on a $150 Kubernetes Lab? I Gave It a Shot
  • Unlocking Data with Language: Real-World Applications of Text-to-SQL Interfaces
  1. DZone
  2. Data Engineering
  3. Data
  4. Add Custom Post Meta Data To Post List Table

Add Custom Post Meta Data To Post List Table

By 
Paul Underwood user avatar
Paul Underwood
·
Apr. 10, 13 · Interview
Likes (0)
Comment
Save
Tweet
Share
13.3K Views

Join the DZone community and get the full member experience.

Join For Free

One of the best thing about WordPress is that you can customise almost anything. In the admin area you can see a list of all the posts you have added in WordPress. Within this table it shows the basic information for each of the posts, the title, the author, the category, tags, comments and the date the post was published.

WordPress has a number of different filters and actions that allow you to edit the output of the column so you can add your own data to this list. For example if you have custom post meta data which is useful information you want to display on the list of posts you can add new custom columns to the list.

In this article you will learn how to add new columns to the post list, how you can add data to the column and how you can make this column sortable.

Add New Columns

First we start off by adding the new column to the list, for this we use the WordPress filter manage_edit-post_columns. This will allow you to edit the output of the columns by adding new values to the column array. The callback function on this filter will pass in one parameter which are the current columns on the list, the return of this function will be the new columns on the post table. This means that we can add additional values to the array to add extra columns to the table.

The following code will add a new column to the table just after the title column.

// Add a column to the edit post list
add_filter( 'manage_edit-post_columns', 'add_new_columns');
/**
 * Add new columns to the post table
 *
 * @param Array $columns - Current columns on the list post
 */
function add_new_columns( $columns ) {
 	$column_meta = array( 'meta' => 'Custom Column' );
	$columns = array_slice( $columns, 0, 2, true ) + $column_meta + array_slice( $columns, 2, NULL, true );
	return $columns;
}

Add Columns To Custom Post Types

If you have custom post types in your site and want to add additional columns to this list, WordPress comes with built in filters you can apply to add new columns to this table.

add_filter( 'manage_${post_type}_posts_columns', 'add_new_columns');

If you have a custom post type of portfolio then you can use the following code to add a column to the list of portfolio post types.

function add_portfolio_columns($columns) {
    return array_merge($columns,
              array('client' => __('Client'),
                    'project_date' =>__( 'Project Date')));
}
add_filter('manage_portfolio_posts_columns' , 'add_portfolio_columns');

Add Data To Custom Columns

Once you have created the new columns for the posts list you can now add data to the new columns by using the WordPress action manage_posts_custom_column. Adding an action to this will be called on each column, from this call we can get data for the post display this on the post list.

The following code will check what column we are on and get the custom post meta data for the current post and display this in the column.

// Add action to the manage post column to display the data
add_action( 'manage_posts_custom_column' , 'custom_columns' );
/**
 * Display data in new columns
 *
 * @param  $column Current column
 *
 * @return Data for the column
 */
function custom_columns( $column ) {
	global $post;
	switch ( $column ) {
		case 'meta':
			$metaData = get_post_meta( $post->ID, 'twitter_url', true );
			echo $metaData;
		break;
	}
}

Add Data To Custom Post Type Columns

Along with being able to add a filter to custom post types by adding new columns, WordPress has a built in action you can use to add data to custom columns.

In the above example we add a new column just for post types of a portfolio to add two new columns to the list, using the below code you can add data to these new columns.

function custom_portfolio_column( $column, $post_id ) {
    switch ( $column ) {
      case 'project_date':
        echo get_post_meta( $post_id , 'project_date' , true );
        break;
      case 'client':
        echo get_post_meta( $post_id , 'client' , true );
        break;
    }
}
add_action( 'manage_portfolio_posts_custom_column' , 'custom_portfolio_column' );

Make Columns Sortable

By default the new custom columns are not sortable so this makes it hard to find data that you need. To sort the custom columns WordPress has another filter manage_edit-post_sortable_columns you can use to assign which columns are sortable.

When this action is ran the function will pass in a parameter of all the columns which are currently sortable, by adding your new custom columns to this list will now make these columns sortable. The value you give this will be used in the URL so WordPress understands which column to order by.

The following to allow you to sort by the custom column meta.

// Register the column as sortable
function register_sortable_columns( $columns ) {
    $columns['meta'] = 'Custom Column';
    return $columns;
}
add_filter( 'manage_edit-post_sortable_columns', 'register_sortable_columns' );

That's all the information you need to change the way posts are listed in your admin area. What useful information do you wish was displayed in the post list?





POST (HTTP) Database Data (computing)

Published at DZone with permission of Paul Underwood, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Advanced Maintenance of a Multi-Database Citus Cluster With Flyway
  • Why Database Migrations Take Months and How to Speed Them Up
  • Unmasking Entity-Based Data Masking: Best Practices 2025
  • Fixing Common Oracle Database Problems

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!