Picture of Add Admin Column in Taxonomy

Add New Terms Admin Column in WordPress

Are you looking for a way to add your custom terms in an admin column? Probably there’s a plugin for this, we have created a code snippet that you can use to create custom terms admin column in WordPress.

Recently I worked on the client website where I created “Properties” Custom Post Type and 2 Custom Taxonomies “States” and “Counties”. The structure is as follow:

  • States linked with Counties
  • Counties linked with Properties

To link states with counties, I created an ACF field to select the state in each county.

Now, the client wants to show the selected state in the admin panel. To do that we are going to use the WordPress filter hook listed below:

// To Add New Column
manage_edit-{custom_taxonomy}_columns

add_filter( 'manage_edit-counties_columns', 'webtut_add_new_counties_columns', 10 );
function webtut_add_new_counties_columns( $columns ) {
    $columns['state'] = __( 'State' );
    return $columns;
}

And action hook to fetch and display values for each field.

manage_{custom_taxonomy}_custom_column

add_action( 'manage_counties_custom_column', 'webtut_show_counties_meta_info_in_columns', 10, 3 );
function webtut_show_counties_meta_info_in_columns( $string, $columns, $term_id ) {
    switch ( $columns ) {
        case 'state' :
            $t_id = esc_html( get_term_meta( $term_id, 'select_state_counties', true ) );
            echo get_term( $t_id )->name;
        break;
    }
}

Add the above code in your theme functions.php file.

Remember that: select_state_counties is an ACF taxonomy field.

Need help? Comment Below.

Leave a Reply

%d bloggers like this: