1

I'm having some issues trying to get taxonomies to appear in the post columns on my dashboard, the custom functions appear correctly, just not the taxonomies, anyone see where I'm going wrong? Here is a screenshot showing the issue: https://i.sstatic.net/KTUN4.png

// Add filters for the Games Database in the control panel
add_filter( 'manage_edit-games_database_columns', 'my_columns' );
function my_columns( $columns ) {
$columns['games_database_platform'] = 'Platform'; // Taxonomy
$columns['games_database_genre'] = 'Genre'; // Taxonomy
$columns['games_database_publisher'] = 'Publisher'; // Custom Function
$columns['games_database_developer'] = 'Developer'; // Custom Function
$columns['games_database_rating'] = 'Review Score'; // Custom Function
unset( $columns['comments'] );
return $columns;
}
add_action( 'manage_posts_custom_column', 'populate_columns' );
function populate_columns( $column ) {
if ( 'games_database_publisher' == $column ) {
    $game_publisher = esc_html( get_post_meta( get_the_ID(), 'game_publisher', true )     );
    echo $game_publisher;
}
elseif ( 'games_database_developer' == $column ) {
    $game_developer = get_post_meta( get_the_ID(), 'game_developer', true );
    echo $game_developer;
}
elseif ( 'games_database_rating' == $column ) {
    $game_rating = get_post_meta( get_the_ID(), 'game_rating', true );
    echo $game_rating . '%';
}
elseif ( 'games_database_platform' == $column ) {
    $game_platform = get_post_meta( get_the_ID(), 'games_database_game_platform', true );
    echo $game_platform;
}
elseif ( 'games_database_rating' == $column ) {
    $game_rating = get_post_meta( get_the_ID(), 'game_rating', true );
    echo $game_rating . '%';
}
}
4
  • Have you tried the parameter 'show_admin_column' => TRUE in register_taxonomy()?
    – fuxia
    Aug 9, 2013 at 10:54
  • @toscho I have now and it has inserted it twice? i.imgur.com/fZyDKZI.png
    – Dave Burns
    Aug 9, 2013 at 11:01
  • You don’t need an extra filter for that anymore.
    – fuxia
    Aug 9, 2013 at 11:03
  • @toscho Add that as an answer and I'll vote it :) Cheers pal!
    – Dave Burns
    Aug 9, 2013 at 11:05

1 Answer 1

2

Call register_taxonomy() with 'show_admin_column' => TRUE and WordPress will create your columns automatically. This parameter was added in version 3.5. You don’t need a custom filter anymore.

I have written a small plugin to demonstrate this case: t5-taxonomy-location.

This is the registration code:

protected function register_taxonomy()
{
    $this->set_labels();

    $args = array (
        'labels'            => $this->labels,
        'label'             => $this->labels['singular_name'],
        'public'            => TRUE,
        'show_in_nav_menus' => TRUE,
        'show_ui'           => TRUE,
        'show_tagcloud'     => TRUE,
        'rewrite'           => array (
            'slug'       => _x( 'location', 'slug', 'plugin_t5_tax_location' ),
            'with_front' => apply_filters( 't5_tax_location_slug_front', FALSE )
        ),
        'query_var'         => 'location',
        'hierarchical'      => TRUE,
        // New in WordPress 3.5
        // see http://core.trac.wordpress.org/ticket/21240
        'show_admin_column' => TRUE
    );

    $tax_post_types = apply_filters(
        't5_tax_location_post_types',
        array( 'post', 'page', 'attachment' )
    );

    register_taxonomy( $this->taxonomy, $tax_post_types, $args );
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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