Skip to content

Instantly share code, notes, and snippets.

@leepettijohn
Created October 26, 2019 00:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leepettijohn/e419d061b7bd35f79ab71f37d055ac7c to your computer and use it in GitHub Desktop.
Save leepettijohn/e419d061b7bd35f79ab71f37d055ac7c to your computer and use it in GitHub Desktop.
Admin View of Post Type - Add ACF field to column
<?php
/* *** add fields from ACF to columns in admin view ****
https://pluginrepublic.com/add-acf-fields-to-admin-columns/
CHANGE
- manage_model_posts_columns (replace "model" with post type slug)
- manage_model_posts_custom_column (replace "model" with post type slug)
- model_order (replace with ACF slug)
*/
function add_acf_columns ( $columns ) {
return array_merge ( $columns, array (
'model_order' => __ ( 'Order' ),
) );
}
add_filter ( 'manage_model_posts_columns', 'add_acf_columns' );
function model_custom_column ( $column, $post_id ) {
switch ( $column ) {
case 'model_order':
echo get_post_meta ( $post_id, 'model_order', true );
break;
}
}
add_action ( 'manage_model_posts_custom_column', 'model_custom_column', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment