0

The title might not be 100% spot on, but let me illustrate what I mean:

I have a custom taxonomy (doens't matter if taxonomy of post-type), and ACF fields registered on the taxonomy. It all works fine, but I am wondering if I can display the key/value (e.g. Type: Candle) next to Name, Description, Slug, Count on the following box:

enter image description here

0

I have this running on my sites as you describe, but I use a plugin for it called Admin Columns. I think their integration with ACF is part of the paid "pro" version, though.

0

You can do this with pages or posts using up to four functions, included here because that's what I've got made to copy and paste for you.

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

The following is for pages (can also be easily applied to posts) in case it helps get you 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 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 there, it's helpful.

In my examples, don't forget to replace items nameofyourcolumn, your_acf_field_name and Name of Your Column.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.