Add ACF Fields to WordPress Admin Columns

Most of the examples for this that I have seen were for adding images to the column area, and did not explain how to fix column content brought in by custom post types.

Trigger by post type:

add_action("manage_[POST_TYPE_NAME]_posts_custom_column", "column_name_function");
add_filter("manage_[POST_TYPE_NAME]_posts_columns", "column_content_function");

Full example:

function add_acf_columns($columns) {
$columns = array(
'cb' => '<input type="checkbox" />',
'title' => 'Title',
'author' => 'Author',
'bulletin' => 'Bulletin #',
'closing_date' => 'Closing Date',
'career_category' => 'Career Type',
'date' => 'Date',
);
return $columns;
}

function career_column_columns($column) {
global $post;

if($column == 'bulletin'){

the_field('bulletin', $post->ID);

} else if($column == 'closing_date') {

the_field('closing_date', $post->ID);

} else if($column == 'career_category') {

$terms = get_the_terms($post->ID, 'career_category');

foreach ($terms as $term) {
echo $term->name;
}

}
}

add_action("manage_careers_posts_custom_column", "career_column_columns");
add_filter("manage_careers_posts_columns", "add_acf_columns");

Source.

Leave a Reply

katherine as a flat graphic icon

About Me

I’m an African / Ojibwe First Nations Web Developer living in Winnipeg, Manitoba.

Visit the Tips and Blog to see what I’m working on.