Custom post type – ACF field key/value to show in taxonomy list

You can do this with Pages or Posts using the four functions included here because that’s what I created for you to copy and paste.

To combine the same thing into a taxonomy, I think you need to do this with manage_edit-tag_columns filter and manage_tag_custom_column action. Here is a resource I found.

The following is for pages (can be easily applied to posts too) if it helps you get to where you’re going.

Function 1: Create a custom column

/**
 * Custom Columns
 * Prints custom column list.
 *
 * @param array $columns is the administration columns visible to the user
 * in the pages dashboard.
 */
function custom_page_columns($columns)
{
    $columns = array(
        'cb'               => '<input type="checkbox" />',
        'title'            => 'Title',
        'nameofyourcolumn' => 'Name of Your Column',
        'author'           => 'Author',
        'date'             => 'Date',
    );
    return $columns;
}
add_action("manage_pages_custom_column", "custom_page_columns");

Function 2: Add your ACF field to that column

/**
 * Custom Columns
 * Adds nameofyourcolumn to columns.
 *
 * @param array $columns is the administration columns visible to the user
 * in the pages dashboard.
 */
function custom_columns($column)
{
    global $post;
    if( $column == 'nameofyourcolumn' ) {
        echo esc_html( get_field( 'your_acf_field_name', $post->ID ) );
    }
}
add_filter("manage_edit-page_columns", "custom_columns");

Function 3: Add the ability to sort this column.

/**
 * Custom Columns
 * Sorts columns.
 *
 * @param array $columns is the administration columns visible to the user
 * in the pages dashboard.
 */
function custom_column_register_sortable( $columns )
{
    $columns['nameofyourcolumn'] = 'nameofyourcolumn';
    return $columns;
}
add_filter("manage_edit-page_sortable_columns", "custom_column_register_sortable" );

Function 4: Add a sort orderby and a meta key to that column.

/**
 * Custom Columns
 * Orders columns alphabetically.
 *
 * @param array $query sorts the nameofyourcolumn column when clicked
 */
function custom_column_orderby( $query ) {
    if( ! is_admin() )
        return;

    $orderby = $query->get( 'orderby');

    if( 'nameofyourcolumn' == $orderby ) {
        $query->set('meta_key','your_acf_field_name');
        $query->set('orderby','meta_value');
    }
}
add_action( 'pre_get_posts', 'custom_column_orderby' );

So technically, you don’t need the last two, but if you want to do some sorting in there, it’s helpful.

In my examples, don’t forget to replace the item your column name, your_acf_field_name And your column name,

Leave a Comment