← All posts

WordPress: add custom, sortable columns to the admin post list

Show a project's client or deadline right in the admin list and let editors sort by it. Four hooks do the job, as long as you avoid two traps we keep running into.

WordPress: add custom, sortable columns to the admin post list

Key points

  • Two hooks add and fill the column; two more make it sortable.
  • Sorting with a plain meta_key silently hides every post that lacks the value.
  • A date saved without a timezone can display one day early; build it with wp_timezone().

Whenever we ship a site with a custom post type (projects, listings, events), the same request turns up a few weeks later: “I have to open every item just to see its deadline.” The WordPress admin list is easy to extend without a plugin. Here is the code we use for a project post type with two fields: the client’s name and a deadline.

Adding and filling the columns

The manage_{post_type}_posts_columns filter hands you the column array. Rather than appending new columns after the date, we slot them in right after the title, where people look first. The manage_{post_type}_posts_custom_column action then prints each cell.

// 1. Declare the columns, inserted right after the title
add_filter( 'manage_project_posts_columns', function ( $columns ) {
    $new = [];
    foreach ( $columns as $key => $label ) {
        $new[ $key ] = $label;
        if ( 'title' === $key ) {
            $new['client']   = __( 'Client', 'wts' );
            $new['deadline'] = __( 'Deadline', 'wts' );
        }
    }
    return $new;
} );

// 2. Print each cell
add_action( 'manage_project_posts_custom_column', function ( $column, $post_id ) {
    if ( 'client' === $column ) {
        echo esc_html( get_post_meta( $post_id, 'client_name', true ) ?: '—' );
    }
    if ( 'deadline' === $column ) {
        $raw  = get_post_meta( $post_id, 'deadline', true ); // stored as Y-m-d
        $date = $raw ? DateTimeImmutable::createFromFormat( '!Y-m-d', $raw, wp_timezone() ) : false;
        echo $date ? esc_html( wp_date( get_option( 'date_format' ), $date->getTimestamp() ) ) : '—';
    }
}, 10, 2 );

For regular posts the hooks are manage_post_posts_columns and manage_post_posts_custom_column. Keep the escaping: these values usually come from a field an editor typed into.

The off-by-one-day trap

On one project every deadline showed up as the day before the one entered. strtotime( '2026-11-15' ) reads the date as midnight UTC, and wp_date() then shifts it into the site’s timezone. If that timezone is behind UTC, midnight becomes the previous evening.

Creating the date in the site’s own timezone with wp_timezone(), as above, fixes it. The ! in the format resets the time to zero instead of borrowing the current time.

Sorting without losing posts

Marking a column as sortable only adds ?orderby=deadline to the URL. Turning that into a query is your job, in pre_get_posts.

// 3. Make the column clickable
add_filter( 'manage_edit-project_sortable_columns', function ( $columns ) {
    $columns['deadline'] = 'deadline';
    return $columns;
} );

// 4. Translate ?orderby=deadline into a meta query that keeps posts without a date
add_action( 'pre_get_posts', function ( WP_Query $query ) {
    if ( ! is_admin() || ! $query->is_main_query() || 'deadline' !== $query->get( 'orderby' ) ) {
        return;
    }
    $query->set( 'meta_query', [
        'relation'      => 'OR',
        'deadline_date' => [ 'key' => 'deadline', 'compare' => 'EXISTS' ],
        [ 'key' => 'deadline', 'compare' => 'NOT EXISTS' ],
    ] );
    $query->set( 'orderby', 'deadline_date' );
} );

The snippet you will find everywhere just sets meta_key and orderby = meta_value. It works, but it filters as a side effect: projects without a deadline vanish the moment you sort. A client once reported “deleted” projects that were simply hidden this way. The OR query with NOT EXISTS keeps every row, and the Y-m-d format means alphabetical order matches chronological order.

What about performance?

Reading one meta value per row is nearly free, because the main query loads the meta for every listed post in one go. The real risks are elsewhere:

  • a get_posts() call or remote API request inside each cell, repeated for every row;
  • sorting on a computed value that is not in the database; store it as post meta on save with save_post instead.

FAQ

Can I add a dropdown filter above the list?

Yes. Use the restrict_manage_posts action to print the dropdown, then apply it in pre_get_posts, exactly like sorting.

Does this work with ACF fields?

Yes, ACF saves regular post meta. Watch the format though: an ACF date picker stores Ymd without dashes, so adjust the parsing format.

Is your WordPress back office slowing your team down? We design custom admin screens around the way your people actually work.

Share LinkedIn Facebook X WhatsApp
</>

webtestudio

Web agency: custom WordPress sites, premium themes and SaaS software.

Discuss your project →