How to add ACF Values to WordPress Admin Columns

acf-admin-columns-wordpress-onepoint-software-solutions-brisbane-australia-blog-2018

Advanced Custom Fields (ACF) allows you to add custom meta fields to a post type or page content in WordPress.

While the plugin can certainly extend your WordPress website, it doesn’t offer admin column support straight out of the box. Enter OnePoint to the rescue!

It can often be helpful to display your meta field ACF values in the dashboard list view for your standard or custom post type. It saves you a lot of time on searching for specific post records, especially if you have a big website.

Let’s say that you have created a post type, ‘conference’, and three custom meta fields, ‘conference_date’, ‘conference_start_time’ and ‘conference_end_time’. You’d like to add all three meta fields (ACF Values) to the custom post type list view:

acf-admin-columns-wordpress-custom-post-type-onepoint-software-solutions-brisbane

First, you will need to add the following snippet to your theme or plugin:

/*
* Add columns to conference post list
*/
function add_acf_columns ( $columns ) {
   return array_merge ( $columns, array ( 
        'conference_date' => __ ( 'Conference Date' ),
        'conference_start_time' => __ ( 'Start Time' ),
        'conference_end_time'   => __ ( 'End Time' ) 
   ) );
 }
 add_filter ( 'manage_conference_posts_columns', 'add_acf_columns' );</pre>

The snippet above contains a filter that extends your conference post type columns list. We have created an array containing three items – for the conference date, start time and end time and merged it with the existing columns for the conference custom post type. This is based on the format manage_POSTTYPE_posts_columns. You’ll need to edit this filter to match your custom post type slug.

Next you will need to add the following code to output the meta field values:

/*
* Add columns to exhibition post list
*/
 function conference_custom_column ( $column, $post_id ) {
   switch ( $column ) {
      case 'conference_date':
       echo get_post_meta ( $post_id, 'conference_date', true );
       break;
     case 'conference_start_time':
       echo get_post_meta ( $post_id, 'conference_start_time', true );
       break;
     case 'conference_end_time':
       echo get_post_meta ( $post_id, 'conference_end_time', true );
       break;
   }
 }
 add_action ( 'manage_conference_posts_custom_column', 'conference_custom_column', 10, 3 );</pre>

In the code snippet above, you will notice how the action hook is specific to your post type, in this case manage_conference_posts_custom_column. The function looks for the name of your custom columns then echoes the meta data. In the action, the 10 represents the priority and the 3 represents the number of arguments.

And there we have it, your ACF meta values should now be visible in your admin columns for your specified post type. Now you can easily view the ACF values without having to click into each individual post.

Need assistance with your WordPress website? Contact our expert web developers today and let’s chat. Call our Brisbane office on 07 3444 0045 or contact us online.

Share on facebook
Share on twitter
Share on linkedin
Share on pinterest
Share on reddit

Contact Us

Sign up for our Newsletter