Add custom column with ACF field to posts and pages admin screen

For a better overview, you may sometimes want to display the value of a ACF custom field in the admin screen of your posts and pages. Adding new custom columns is simple.

Let’s assume you have an ACF field which has the field name “my-custom-acf-field”. All you need to do is registering the new column in your functions.php:

function add_new_posts_admin_column($column) {
    $column['my-custom-acf-field'] = 'My custom ACF field';

    return $column;
}

add_filter('manage_posts_columns', 'add_new_posts_admin_column');

function add_new_posts_admin_column_show_value($column_name) {
    if ($column_name == 'my-custom-acf-field') {
        echo get_field('my-custom-acf-field');
    }
}

add_action('manage_posts_custom_column', 'add_new_posts_admin_column_show_value', 10, 2);

 

The code above adds a new column to your posts admin screen.

In addition you can make the new admin column sortable. Simply add the following lines of code:

function add_new_posts_admin_columns_make_sortable($columns)
{
    $columns['my-custom-acf-field'] = 'my-custom-acf-field';

    return $columns;
}

add_filter("manage_edit-post_sortable_columns", "add_new_posts_admin_columns_make_sortable" );

 

This is it!

If instead you would like to add your column to your pages admin screen, in the first code block please replace “manage_posts_columns” with “manage_pages_columns” (line 7) and “manage_posts_custom_columns” with “manage_pages_custom_columns” (line 15) and in the second code block “manage_edit-post_sortable_columns” with “manage_edit-page_sortable_columns” (line 9).

 

3 thoughts on “Add custom column with ACF field to posts and pages admin screen”

  1. Really nice! Thanks for this clear and useful code. Exactly what I was looking for. I simply created a field and didn’t want to use a huge plugin (Admin Columns) to add it to pages columns. The only thing, do you know how to modify the location of the column? Because with your code, by default it add the custom column at the end, and I would like to position it as the second of the list. Thanks.

Leave a Reply

Your email address will not be published. Required fields are marked *