WordPress.org

Ready to get started?Download WordPress

Forums

List Custom Taxonomies in Custom Columns (4 posts)

  1. ryansigg
    Member
    Posted 3 years ago #

    I have run into trouble populating the custom columns on the edit.php page of a custom post type.
    I know there is plenty of discussion on this subject already, but I believe I'm running into a unique problem.

    At first I thought I just couldn't get the custom taxonomy to populate the columns, but now it seems that I can't get any of the columns in my custom post type to populate at all (ie. even when filled with test echo statements).

    here's the full code:
    http://wordpress.pastebin.com/FbGsy1zv

    Note that the top two cases under switch contain test echos, none of which shows up in the columns.

    So, I have installed this code on two sites (one that runs the Hybrid theme framework) and I get two different results. On the 1st/Hybrid one, the fields do no populate at all. On the second one the fields will populate if I select "Quick Edit" and hit "Update"; if I refresh the page the column content disappears (note, this problem is similar to the problem noted by Bennst here.)

    Any help would be greatly appreciated.

  2. paulehpants
    Member
    Posted 3 years ago #

    Your custom post type must be set to 'hierarchical' => false

  3. alex chousmith
    Member
    Posted 3 years ago #

    check out this article : http://themehybrid.com/support/topic/add-custom-taxonomy-to-editphp

    since your Custom Post Type is 'cruise' and your Custom Taxonomy in this case is 'destination', something like this should work:

    add_action("manage_posts_custom_column",  "show_destinations_column");
    add_filter("manage_edit-cruise_columns", "cruise_columns");
    
    function cruise_columns($columns){
      $columns = array(
        "cb" => "<input type=\"checkbox\" />",
        "title" => "Title",
        "categories" => "Categories",
        "destination" => "Destination",
        "test_id" => "ID",
      );
    
      return $columns;
    }
    function show_destinations_column($column){
      global $post;
    
      switch ($column) {
        case "destination":
    	  echo get_the_term_list($post->ID,'destination','',', ','');
          break;
        case "test_id":
    	  echo "test ID";
          break;
      }
    }
  4. ryansigg
    Member
    Posted 3 years ago #

    Thanks for the help...
    @paulehpants: It's a hierarchical post type, and that IS what was causing some of the problem (in the action, not the filter)...

    For pages and hierarchical custom post types you can use the following action triggers:
    manage_pages_custom_column
    For posts it's still:
    manage_posts_custom_column
    For both non-hierarchical custom types and hierarchical custom types:
    manage_{$post->post_type}_posts_custom_column

    In the end (I solved this a while ago but failed to follow up) I used pretty much the same as the above from alex,
    paulehpants
    add_action('manage_cruise_posts_custom_column', 'show_destinations_column');

Topic Closed

This topic has been closed to new replies.

About this Topic