Skip to content

Instantly share code, notes, and snippets.

@woraperth
Last active June 9, 2018 10:19
Show Gist options
  • Save woraperth/fce00a22e7dbab57ca5cb4b4d2cfa2e1 to your computer and use it in GitHub Desktop.
Save woraperth/fce00a22e7dbab57ca5cb4b4d2cfa2e1 to your computer and use it in GitHub Desktop.
[WordPress] Add ACF Admin Column to taxonomy (In this example, taxonomy name = product_category & ACF column name = english_name)
// Add ACF Columns
function add_new_product_cat_column($column) {
$column['english_name'] = 'English Name';
return $column;
}
add_filter('manage_edit-product_category_columns', 'add_new_product_cat_column');
function add_new_product_cat_admin_column_show_value( $content, $column_name, $term_id ) {
if ($column_name == 'english_name') {
$content = get_field('english_name', 'product_category_' . $term_id);
return $content;
}
return $content;
}
add_filter('manage_product_category_custom_column', 'add_new_product_cat_admin_column_show_value', 10, 3);
@changuelsami
Copy link

How can I make it sortable ?
Thanks 👍

@changuelsami
Copy link

changuelsami commented Jun 9, 2018

I've added this :

function sort_new_product_cat_column($column) {
    $column['english_name'] = 'english_name';
    //                         ^^^^^^^^^^^^^
    return $column;
}
add_filter('manage_edit-product_category_sortable_columns', 'sort_new_product_cat_column');
//                                       ^^^^^^^^^

The new column is clickable, but the sorting is wrong

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment