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");<br>add_filter("manage_[POST_TYPE_NAME]_posts_columns", "column_content_function");

Full example:

function add_acf_columns($columns) {<br>$columns = array(<br>'cb' => '<input type="checkbox" />',<br>'title' => 'Title',<br>'author' => 'Author',<br>'bulletin' => 'Bulletin #',<br>'closing_date' => 'Closing Date',<br>'career_category' => 'Career Type',<br>'date' => 'Date',<br>);<br>return $columns;<br>}<br><br>function career_column_columns($column) {<br>global $post;<br><br>if($column == 'bulletin'){<br><br>the_field('bulletin', $post->ID);<br><br>} else if($column == 'closing_date') {<br><br>the_field('closing_date', $post->ID);<br><br>} else if($column == 'career_category') {<br><br>$terms = get_the_terms($post->ID, 'career_category');<br><br>foreach ($terms as $term) {<br>echo $term->name;<br>}<br><br>}<br>}<br><br>add_action("manage_careers_posts_custom_column", "career_column_columns");<br>add_filter("manage_careers_posts_columns", "add_acf_columns");


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.