Add Custom Taxonomy Columns to Edit Posts Page

WordPress’s Edit Posts Page pretty much shows information you need to use. But with the inclusion of Custom Taxonomies from WordPress 2.8, it becomes difficult to check which posts are using which Taxonomies unless you edit each post manually. To make the job of editing custom taxonomies easy, its better if we could see all our custom taxonomies on Edit Posts page too. Well there are several tutorials on web which will tell you how to add custom columns to the Edit Posts Admin page but none tells you exact method for adding Custom Taxonomies column. Let me take through a walkthrough of it.

Big Help to This post at Themehybrid for the idea and code. The following tutorial adds 2 columns to add Films and Language [picked from one of my video blogs] (with the custom taxonomy slugs as film and lang) taxonomies to Edit Posts Admin Page. [Works on WordPress 2.9 and 3.0]

Open your Theme’s functions.php file and add the following code just before the last ?>:

To learn about Custom Taxonomy, I would suggest reading this post by Justin Tadlock covering basics of Custom Taxonomies in WordPress 2.8. Any questions, please post in comments.

11 Comments

  1. Karen Turner

    Thanks so much, I have been searching for days to sort this out, it worked instantly. Amazing.


    1. Navjot Singh

      Only WordPress.


  2. Thank you so much for sharing this code!

    I´ve got some special kind of lines for you. Use this for Custom Post Type Columns with custom taxonomy:

    ID, ‘genre’); //genre is the first custom taxonomy slug
    if ( !empty( $tags ) ) {
    $out = array();
    foreach ( $tags as $c )
    $out[] = “slug&post_type=portfolio’> ” . esc_html(sanitize_term_field(‘name’, $c->name, $c->term_id, ‘commercials’, ‘display’)) . ““;
    echo join( ‘, ‘, $out );
    } else {
    _e(‘No Genre.’); //No Taxonomy term for ‘Genre’ defined
    }
    }

    else if( $column_name == ‘actor’ ) { //Adding 2nd column
    $tags = get_the_terms($post->ID, ‘actor’); //actor is the next taxonomy slug for column Films
    if ( !empty( $tags ) ) {
    $out = array();
    foreach ( $tags as $c )
    $out[] = “slug&post_type=portfolio’> ” . esc_html(sanitize_term_field(‘name’, $c->name, $c->term_id, ‘actor’, ‘display’)) . ““;
    echo join( ‘, ‘, $out );
    } else {
    _e(‘No Related Actor.’); //no Actors found
    }
    } else {
    echo ‘‘.__(‘None’).’‘; //Only 2 columns, blank now.
    }
    }
    ?>

    1. Navjot Singh

      Will check this asap. :) Thanks for sharing.

  3. [Keyword Removed]

    Thank you, it’s great to be able to add a column for a custom taxonomy to the Edit Posts page, showing which terms are used for each post. But what I’d REALLY like to have is a DROPDOWN FILTER above the listed posts, so i can easily find which posts use a certain term for a taxonomy (just like how we already have one for Categories). Any thoughts on that?

    Even better would be a conditional dropdown where the 1st dropdown has all my custom taxonomies, and when one is selected, then 2nd dropdown populates with all the terms from the selected taxonomy. I’d love to write that plugin (if i had a clue how).

    1. DGB

      To add a dropdown filter, you need to create your own select menu control:
      [php]
      function my_restrict_manage_posts() {
      global $typenow;
      if ($typenow==’my_custom_post_type’)
      echo get_taxonomy_html_select(‘my_taxonomy’);
      }

      function get_taxonomy_html_select($taxonomy_name) {
      $taxonomy = get_taxonomy($taxonomy_name);
      $terms = get_terms($taxonomy_name);
      $label = "Show All {$taxonomy->label}";
      $html = array();
      $html[] = "<label for=\"$taxonomy_name\"> Audience:</label>";
      $html[] = "<select id=\"$taxonomy_name\" name=\"$taxonomy_name\">";
      $html[] = "<option value=\"0\">$label</option>";
      $this_term = get_query_var($taxonomy_name);
      foreach($terms as $term) {
      $default = ($this_term==$term->slug ? ‘ selected="selected"’ : ”);
      $value = esc_attr($term->name);
      $html[] = "<option value=\"{$term->slug}\"$default>$value</option>";
      }
      $html[] = "</select>";
      return implode("\n",$html);
      }
      [/php]

  4. tinus2

    running 3.0 beta 1, it’s not displaying any custom taxonomy columns adding this to my function.php – do you know further ressources other than custom taxonomy plugins which I wanted to avoid?

    1. Navjot Singh

      Have you tried disabling each plugin one by one and checked which plugin causes conflict with this? I am still using it on WordPress 3.0 beta 1 on my Video blog.


Comments are closed.