Shiba

Adventures in WordPress

  • — Home —
  • Dog
  • Art
  • Contact
  • WordPress Articles
    • WP Plugins
    • WP Programming
    • WP Admin Panels
    • WP Theme Design
    • WP How-To
    • WP Theme Images
You are here: Home / WordPress Admin / Custom Post Type / Add Custom Post Type Columns

Add Custom Post Type Columns

Tweet

by ShibaShake 88 Comments

One of the exciting new features in WordPress 3.0 is custom post types. We can create our own post types by using the register_post_type function.

If we enable UIs for our custom post type, we will get additional menu items on our WordPress dashboard similar to the Edit and Add New options for standard posts.

Here, we consider how to add new columns to the Edit custom post type screen.

1. Create a Custom Post Type

Creating a custom post type is surprisingly straight-forward and well documented in the WordPress Codex.

In this example, we create a custom post type called gallery.

	$labels = array(
		'name' => _x('Galleries', 'post type general name'),
		'singular_name' => _x('Gallery', 'post type singular name'),
		'add_new' => _x('Add New', 'gallery'),
		'add_new_item' => __("Add New Gallery"),
		'edit_item' => __("Edit Gallery"),
		'new_item' => __("New Gallery"),
		'view_item' => __("View Gallery"),
		'search_items' => __("Search Gallery"),
		'not_found' =>  __('No galleries found'),
		'not_found_in_trash' => __('No galleries found in Trash'), 
		'parent_item_colon' => ''
	  );
	  $args = array(
		'labels' => $labels,
		'public' => true,
		'publicly_queryable' => true,
		'show_ui' => true, 
		'query_var' => true,
		'rewrite' => true,
		'capability_type' => 'post',
		'hierarchical' => false,
		'menu_position' => null,
		'supports' => array('title','thumbnail','excerpt')
	  ); 
	  register_post_type('gallery',$args);
New gallery custom post type menu items and Edit screen.
New gallery custom post type menu items and Edit screen.

2. Add New Custom Post Type Columns

As shown in the screen-shot above, our custom post type Edit screen (called Gallery) starts off with four columns – checkbox, Title, Author, and Date.

To add new columns to our Edit screen, we want to hook into the manage_$pagename_columns filter. The $pagename of the Edit screen is edit-$post_type.

Therefore, in this example, –

  • Edit page name = edit-gallery
  • Add column filter hook = manage_edit-gallery_columns

Our add column function call looks like this –

// Add to admin_init function
add_filter('manage_edit-gallery_columns', 'add_new_gallery_columns');

Our filter function accepts an array of column names, and returns our new column array once we are done.

	function add_new_gallery_columns($gallery_columns) {
		$new_columns['cb'] = '<input type="checkbox" />';
		
		$new_columns['id'] = __('ID');
		$new_columns['title'] = _x('Gallery Name', 'column name');
		$new_columns['images'] = __('Images');
		$new_columns['author'] = __('Author');
		
		$new_columns['categories'] = __('Categories');
		$new_columns['tags'] = __('Tags');
	
		$new_columns['date'] = _x('Date', 'column name');
	
		return $new_columns;
	}

In the example above we fully replace the column array with our own entries. We can also just add columns by adding new elements into the existing $gallery_columns array. However, our added columns will only appear after the existing default columns.

The functions above will add new columns into our Edit Gallery screen which now looks like this –

Gallery screen with new custom post type columns.
Gallery screen with new custom post type columns.

If we want the column to be sortable, then we can use the manage_{$screen->id}_sortable_columns filter. Here is a good example for making sortable columns.

3. Render Our New Custom Post Type Columns

Note – In the screen-shot above, the ID and Images columns are empty because they are not standard WordPress post columns. Standard WordPress post columns include –

  • ‘cb’ – Post checkbox.
  • ‘date’ – Date when post was last modified.
  • ‘title’ – Post title and common post actions including Edit, Quick Edit, Trash, and View.
  • ‘categories’ – Post categories.
  • ‘tags’ – Post tags.
  • ‘comments’ – Number of post comments.
  • ‘author’ – Post author.

To render our new columns, ‘id’ and ‘images’, we must hook into the manage_posts_custom_column action (in WordPress 3.0).

In WordPress 3.1, we want to hook into the manage_{$post_type}_posts_custom_column action. Since our example post type is gallery, we want to hook into manage_gallery_posts_custom_column.

        // Add to admin_init function
	add_action('manage_gallery_posts_custom_column', 'manage_gallery_columns', 10, 2);

	function manage_gallery_columns($column_name, $id) {
		global $wpdb;
		switch ($column_name) {
		case 'id':
			echo $id;
		        break;

		case 'images':
			// Get number of images in gallery
			$num_images = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM $wpdb->posts WHERE post_parent = %d;", $id));
			echo $num_images; 
			break;
		default:
			break;
		} // end switch
	}	

Our ‘id’ and ‘images’ columns will now be rendered with the proper values.

Render new custom post type columns with the proper data.
Render new custom post type columns with the proper data.

We Are Done!

Another interesting action hook in the Edit screen page is restrict_manage_posts which allows us to control which custom post objects we want to show on the page.

And just like that … we are done!

Related Articles

Modify Custom Taxonomy Columns

How to expand our taxonomy screens by adding new columns.

Add a Metabox to Your Custom Post Type Screen

How to add our own metabox to the edit custom post type screen.

Custom Post Type Permalinks - Part 2

How to fully customize and create our own permalinks for custom post type objects.

Comments

  1. Joe says

    August 23, 2016 at 3:47 pm

    “Cannot use object of type stdClass as array in”
    // Set total count
    $count = absint( $json[0]->total_count );

    any idea why this stopped working? or a good fix? thanks

    Reply
  2. Laura says

    April 22, 2016 at 11:43 am

    This was exactly what I was looking for for my custom post type, however I’m a tad bit lost as to where these functions are inserted. Are they part of the custom post type function itself? Or are they separate functions? Also, regardless of where I put the code, I get an error with the first line “admin_init function”. Pretty sure I’m missing something right before that? Thanks in advance.

    Reply
    • Laura says

      April 22, 2016 at 11:54 am

      Oy…nevermind…I hadn’t copied the line right. It was a comment. SMH at myself.

      Reply
  3. ashmichmore says

    February 10, 2016 at 1:22 am

    Thank you so much!!!!!!!

    Reply
  4. Muhammad Uzair says

    January 26, 2016 at 11:27 pm

    plzzzz tell me the code for categories how to show categories whicj product is coming from category i m waiting

    Reply
  5. Mike says

    November 17, 2015 at 8:58 am

    Great post, thanks!

    For those who would rather not go through the custom coding, a great plugin I found that does exactly what this coding accomplishes, AND provides flexibility and a GUI interface is: “Admin Columns” (admincolumns.com).

    No, I have nothing to do with the creation of the plugin, just a happy user. There is a Pro version, but the free version did what I needed.

    Reply
  6. uddav says

    April 23, 2015 at 11:09 pm

    Really great article. I was looping around two days for this and finally found this great article and solved my problem.
    Thanks ShibaShake

    Reply
  7. sam says

    December 7, 2014 at 2:10 am

    what i’m looking for 🙂

    cheers

    Reply
  8. Nuthan Raghunath says

    November 8, 2014 at 10:44 pm

    Does images column render values? Iam getting error Warning: Missing argument 2 for wpdb::prepare().

    Reply
    • ShibaShake says

      November 12, 2014 at 11:29 pm

      Yeah, the wpdb::prepare syntax has changed. You want to do something like this-

      $wpdb->prepare("SELECT COUNT(*) FROM $wpdb->posts WHERE post_parent = %d;", $id)
      
      Reply
  9. Lewis Sherlock says

    August 22, 2014 at 2:49 am

    Great article.

    Although I was tearing my hair out trying to get my columns for custom fields to work.
    For those using custom fields IE inputs etc make sure you use the following line of code in the manage_custom_columns function

    $custom = get_post_custom($post->ID);

    as shown in my function below:

    function product_custom_columns($column) {
    global $post;
    $custom = get_post_custom($post->ID);
    switch ($column) {
    case “price”:
    echo $custom[“price”][0];
    break;
    case “manufacture”:
    echo $custom[“manufacture”][0];
    break;
    case “Product categories”:
    echo get_the_term_list($post->ID, ‘Product categories’, ”, ‘, ‘,”);
    break;
    }
    }

    Reply
  10. Dipankar Barman says

    April 4, 2014 at 3:22 am

    Hi Author!

    It is a awesome tutorial. it help me lot to make custom post type in my site.
    thanks for your code. it’s working fine.

    Reply
  11. Janes Oosthuizen says

    May 30, 2013 at 12:53 pm

    Hey, This is a awesome tutorial. I have read a few tutorials on this topic. Yours is the most thorough and easy to understands Well Done!

    Reply
  12. Momo says

    April 28, 2013 at 2:37 am

    i use this code don’t display ma customs posts categoriers please helpe me
    //’manage_career_posts_custom_column’,
    add_filter(‘manage_career_posts_custom_column’,’add_new_career_columns’);
    function add_new_career_columns($career_columns) {
    $new_columns[‘title’] = _x(‘Title post’);
    $new_columns[‘author’] = __(‘Author’);
    $new_columns[‘categories’] = __(‘Categories’);
    $new_columns[‘tags’] = __(‘Tags’);
    $new_columns[‘date’] = _x(‘Date’);
    return $new_columns;
    }

    Reply
  13. Makarand Mane says

    January 7, 2013 at 2:55 am

    Hi i want add post thumbnail in images column

    then what will be query to called

    Reply
    • moya says

      January 19, 2013 at 7:57 pm

      I apologize my script tags were being parsed as html. here is the code again

      switch ($column_name) {
      case ‘images’:
      $thumnail_id = get_post_thumbnail_id($id);
      $imgsrc = wp_get_attachment_image_src($thumnail_id, ‘thumbnail’);

      if ( has_post_thumbnail($id) ) {
      echo ”;
      ;
      }

      break;
      default:
      break;
      }

      Reply
  14. Danyo says

    August 22, 2012 at 2:55 am

    Great Tutorial!

    How would i go about making the column names clickable to order by asc or desc like you would on the standard post screen?

    Thanks, Danyo

    Reply
    • ShibaShake says

      August 22, 2012 at 7:38 am

      Use the manage_{$screen->id}_sortable_columns filter. Good example for doing that here-

      http://wordpress.org/support/topic/admin-column-sorting

      Reply
  15. CGP says

    May 28, 2012 at 1:30 am

    Thank you very much.. This helps me a lot.

    Reply
  16. Ryan says

    May 18, 2012 at 9:06 am

    Thanks for this. Always great to find a short and simple explanation.

    Reply
  17. Wesam Alalem says

    April 13, 2012 at 9:57 am

    Thanks a lot, this helped me to add columns to a custom post type table in no time 😉

    Reply
  18. Slob Jones says

    March 20, 2012 at 7:58 pm

    What about adding a column for custom taxonomies, as well as for categories?

    Reply
  19. Sigondrong dari Gua Hiro says

    January 25, 2012 at 4:07 am

    If we make a custom post type, so we also may have a different field to be edited. How to insert custom field (may be, not as postmeta but taken from different table) in edit post page?
    ie in: /wp-admin/post.php?post=xx&action=edit

    Reply
    • ShibaShake says

      January 25, 2012 at 10:55 am

      http://shibashake.com/wordpress-theme/add-metabox-custom-post-type

      Reply
    • Sigondrong dari Gua Hiro says

      January 25, 2012 at 4:08 pm

      I found this link http://codex.wordpress.org/Function_Reference/add_meta_box
      This is what I want.

      Reply
    • Sigondrong dari Gua Hiro says

      January 25, 2012 at 4:13 pm

      But http://shibashake.com/wordpress-theme/add-metabox-custom-post-type is very good. Thanks a lot.

      Reply
  20. Erik F says

    December 13, 2011 at 12:13 am

    Wonderful, this solves many of my problems. However, I have a question, how do I show the galleries for the visitor? Is it through single.php?

    Reply
    • Erik F says

      December 14, 2011 at 4:05 am

      When I try to look at my new gallery, I see only what’s in 404.php. What am I doing wrong? Is there any way I can list all the galleries on one page (such as posts)?

      Reply
      • ShibaShake says

        January 4, 2012 at 3:07 pm

        When you say new gallery, are you using the WordPress native gallery or the gallery object from Shiba Media Library? When you edit the gallery in the dashboard, do all the images show up? What do you have your gallery permalink set to?

        Reply
  21. Hatem says

    November 26, 2011 at 11:28 pm

    Thanx , your post is so great. But i have a Q related to categories columns. It is all time (uncategorized) even if the custom type post categorized !!

    How i can solve this ?!

    Reply
    • iain says

      February 9, 2012 at 1:51 pm

      Hi did you ever find an answer to this?

      Reply
      • iain says

        February 9, 2012 at 1:57 pm

        http://www.ilovecolors.com.ar/add-taxonomy-columns-custom-post-types-wordpress/

        Just seen this links!!!! works well!!! hope it helps

        Reply
  22. Abzal says

    September 28, 2011 at 7:56 am

    Hey, nice article! I am planning to create custom post types for Restaurants with menus and others things. I am unsure of having one CPT or many; say one for Restaurant, menus and later Location.

    Thank you!

    Reply
  23. Greg says

    September 23, 2011 at 9:40 am

    Great post — it’s unbelievable the amount of Googling I had to do to find a satisfactory (and clear!) method to do this. Thanks for letting me end my search!

    Reply
    • ShibaShake says

      September 23, 2011 at 11:16 am

      Glad to be of service. 🙂

      Reply
  24. wp_harish says

    September 22, 2011 at 4:40 am

    Hey thanks very much..
    I am eager to know how Can we add functionality to custom column for sorting of posts…just like Title and Date columns come by default..

    Reply
    • ShibaShake says

      September 23, 2011 at 11:08 am

      Use the “manage_{$screen->id}_sortable_columns” filter.

      Reply
  25. prajesh says

    September 15, 2011 at 4:01 am

    Very useful article

    Reply
  26. George Stephanis says

    September 7, 2011 at 7:54 am

    Here’s what I did to insert two columns in the middle of a custom post type table … which is also more extensible, as it lets other plugins do the same:

    
    	function add_new_columns( $cols ){
    		return array_merge(
    			array_slice( $cols, 0, 2 ),
    			array( 	'subtitle' => __('Subtitle'),
    					'pub_date' => __('Publication Date') ),
    			array_slice( $cols, 2 )
    		);
    	}
    

    If you wanted to be even pickier, instead of hardcoding `2` for after the second column, you could use something to find the index of the associative key, either directly or by snatching an array of the keys and searching in there with array_keys();

    Reply
  27. toy says

    July 19, 2011 at 9:02 am

    this was awesome!
    thanks so much

    Reply
  28. Andrea says

    July 15, 2011 at 2:08 am

    great tutorial!
    i have a question: i want to let the user order post by a custom field value, insted of simply show the value of that custom field.
    Thank you

    Reply
    • ShibaShake says

      July 18, 2011 at 12:38 pm

      Use the manage_{$screen->id}_sortable_columns filter. E.g., ‘manage_edit-gallery_sortable_columns’.

      Reply
  29. Nuwanda says

    April 13, 2011 at 1:52 am

    Ok, this sorta works for my custom post type.

    But I have a custom taxomony instead of the normal wordpress categories.

    How do I show the custom taxonomy that the post belongs to?

    If my custom taxonomy is Cars, I’m using…

    $new_columns[‘cars’] = __(‘Car’);

    ..but all I’m getting is the header and no taxonomy listed.

    Reply
    • ShibaShake says

      April 17, 2011 at 11:54 am

      You need to fill in the column values yourself by hooking into the manage_{$post_type}_posts_custom_column action.

      Check out section 3 in the article above.

      Reply
      • Trewknowledge says

        June 8, 2011 at 2:52 pm

        I am also having a problem displaying the right category. I have a custom post called “slider” so I wrote out
        manage_slider_posts_custom_column

        However all of the posts say “Uncategorized”. All of the posts have a “Slider Category” associated with it.

        Any thoughts?

        Reply
        • ShibaShake says

          June 13, 2011 at 2:52 pm

          It is difficult to say without looking at the code.

          First, I would just do an “echo blah” to see if your manage_slider_posts_custom_column function is being called. If the function is being called, then likely, there is some bug while extracting the category values from the slider objects.

          Reply
  30. Dan says

    March 28, 2011 at 5:06 am

    Hi, I just used part of this code to add thumbnails to my custom post types. I used get_the_post_thumbnail($post-ID,array(100,100)); in the switch part for a column I made called image. Worked an absolute treat.

    Epic post, thanks.

    Reply
    • Dan says

      March 28, 2011 at 5:07 am

      whoops, I meant $post->ID. Im always missing the “>” out, bad habit!

      Reply
  31. Adedoyin Kassem says

    February 28, 2011 at 12:34 am

    Thanks for this post, it has been very enlightening. However i have got just one challenge using this feature. I have a custom post type for events and i use this code (below) to create custom columns:

    function add_new_events_columns($event_columns) {
    $new_columns[‘cb’] = ”;
    $new_columns[‘title’] = _x(‘Event Name’, ‘column name’);
    $new_columns[‘location’] = _x(‘Event Location’, ‘column name’);
    $new_columns[‘events_date’] = _x(‘Event Date’, ‘column name’);
    $new_columns[‘date’] = _x(‘Date Posted’, ‘column name’);
    return $new_columns;
    }

    The columns show perfectly well. However, when i tried to call out the content of the location meta box using this code:

    function manage_events_columns($column_name, $id) {
    global $wpdb;
    switch ($column_name) {
    case ‘location’:
    $location_meta = get_post_meta($post->id, ‘location’, true);
    echo $location_meta;
    break;
    }
    }

    I can’t seem to use this method to get the content of the meta boxes to show in the respective columns. Please, i need help on this.

    Reply
    • ShibaShake says

      February 28, 2011 at 7:50 am

      In the code above you did not set $post. Try just using $id.

      Reply
  32. Matt says

    February 26, 2011 at 8:00 am

    Is it possible to add custom meta field values to the columns? I would like to set _lastname, _firstname as the title. Thanks Shibashake!

    Reply
    • ShibaShake says

      February 28, 2011 at 7:52 am

      You should be able to display whatever you want by putting it into the manage_gallery_columns function.

      Reply
  33. Joe says

    January 4, 2011 at 3:13 pm

    Just confirmed: everything is fine in 3.1 RC2 except that If the custom post type is registered as ‘hierarchical’ => true, then the column will not populate with the data.

    Reply
    • Kcssm says

      January 7, 2011 at 2:54 am

      Yes I also got the same problem. The columns doesnot get populated when the `‘hierarchical’ => true` is set. Looking for a solution.

      Thanks..

      Reply
      • ShibaShake says

        January 10, 2011 at 10:29 pm

        For hierarchical custom post types in WP 3.1 try using –
        add_action(‘manage_pages_custom_column’, ‘manage_gallery_columns’, 10, 2);

        or you can also use –
        add_action(“manage_{$post->post_type}_posts_custom_column”, ‘manage_gallery_columns’, 10, 2);

        Reply
        • alex chousmith says

          February 7, 2011 at 10:48 pm

          in WP 3.0.4, this is also the solution to this problem.

          basically, if your custom post type IS hierarchical, the action hook is “manage_pages_custom_column”. if you did not specificy “hierarchical” => true in the register_post_type , it is by default FALSE, and you can hook to custom columns via the “manage_posts_custom_column” as shown in this post

          good times

          Reply
  34. Joe says

    January 4, 2011 at 2:33 pm

    Seems like WordPress 3.1 RC2 is having issues echoing the value. Was fine on RC1. Anyone else notice?

    Reply
  35. Team Roster says

    October 29, 2010 at 5:51 pm

    You you could edit the webpage name title
    Add Custom Post Type Columns to something more catching for your webpage you write. I loved the post yet.

    Reply
  36. Dasha says

    October 19, 2010 at 10:11 am

    I was also wondering what’s the difference between:

    $new_columns[‘title’] = _x(‘Gallery Name’, ‘column name’);

    and

    $new_columns[‘categories’] = __(‘Categories’);

    What does ‘column name’ when specified?

    Thanks.

    Reply
    • ShibaShake says

      October 20, 2010 at 9:51 am

      _x pertains to doing translations within WP. I really didn’t need to use it above. Likely, it was carry-over from some native code that I was looking at.

      Here is a bit more on _x
      http://phpdoc.wordpress.org/trunk/WordPress/i18n/_wp-includes—l10n.php.html#function_x

      Reply
    • Travis says

      October 21, 2010 at 9:31 am

      I was wondering how one would add an edit function to each object in the custom category, just like the functionality on the standard post columns.

      Thanks!

      Reply
      • ShibaShake says

        October 24, 2010 at 9:15 pm

        Try using the post_row_actions filter. Alternatively, you can create your own ‘title’ column by patterning it after the post ‘title’ column.
        http://phpxref.ftwr.co.uk/wordpress/nav.html?wp-admin/includes/list-table-posts.php.source.html#l475

        Reply
  37. Dasha says

    October 19, 2010 at 8:32 am

    Thanks for the great article, so hard to find tutorials on this topic!

    I have 2 post types: ‘Portfolio’ (with meta_data) and ‘Client’. I’m adding custom columns to ‘Portfolio’ admin edit page:

    add_filter(‘manage_edit-portfolio_columns’, ‘add_new_portfolio_columns’);
    function add_new_portfolio_columns($portfolio_columns) {
    $new_columns[‘cb’] = ”;

    $new_columns[‘title’] = _x(‘Portfolio Title’, ‘column name’);
    $new_columns[‘portfolio_types’] = __(‘Portfolio Types’); //Portfolio taxonomy
    $new_columns[‘client’] = __(‘Client’); //reference Client post type via ‘client_id’ in Portfolio meta
    $new_columns[‘testimonial’] = __(‘Testimonial’); //Portfolio meta into
    $new_columns[‘date’] = _x(‘Date’, ‘column name’);

    return $new_columns;
    }

    I have a problem that I can’t understand. I’ve specified my custom columns, all good, and here is the method that I use to populate the columns. It seems that after extracting ‘client_id’ from ‘Portfolio’ meta and finding ‘Client’ post type things go wrong. Because for the next column I’m exctracting ‘testimonial’ from ‘Portfolio’ meta, but it seems that $post is now a ‘Client’ post.

    add_action(‘manage_posts_custom_column’, ‘manage_portfolio_columns’, 10, 2);
    function manage_portfolio_columns($column_name, $post_id) {
    global $wpdb, $post, $key;

    switch ($column_name){
    // PORTFOLIO post type columns
    case ‘portfolio_types’:
    $terms = get_the_term_list($post->ID , ‘portfolio_type’ , ” , ‘, ‘ , ” );
    if(is_string($terms)) {
    echo $terms;
    }
    break;
    case ‘client’:
    $portfolio_meta = get_post_meta($post->ID, $key, true);
    $client_id = $portfolio_meta[‘client_id’];
    // client specified – display his name
    if($client_id){
    $client = new WP_Query(“post_type=client&p=$client_id”);
    //this loop seems to scrue up the value of $post for the following column… instead of ‘Portfolio’ post type, I somehow getting ‘Client’ and I dont understand why
    if($client->have_posts()) { while($client->have_posts()) { $client->the_post();
    the_title();
    }
    }
    }
    break;
    case ‘testimonial’:
    $portfolio_meta = get_post_meta($post->ID, $key, true);
    echo $post_id;
    $testimonial = $portfolio_meta[‘testmonial’];
    if($testimonial){
    echo $testimonial;
    }
    break;
    default:
    break;
    }
    }

    Would really appreciate any help!
    Thanks.

    Reply
    • ShibaShake says

      October 20, 2010 at 9:42 am

      Do you have a column named client for your Client post type as well? If so, there could be problems.

      The manage_posts_custom_column gets called while rendering *all* post type objects including posts, pages, and custom post types. You could do a post_type check in the beginning of the function to limit the scope of its operation.

      Reply
  38. RedsPriesee says

    October 15, 2010 at 5:14 pm

    Hi, it’s nice here so I am just saying hi. I’ve been reading forum for a moment now.

    Reply
  39. Leo says

    September 22, 2010 at 11:53 am

    This is the code I used:

    First adding this to function.php:
    add_theme_support(‘post-thumbnails’);
    add_image_size( ‘release-post-thumbnail’, 95, 95 ); //Custom Thumbnail size

    Then this is my case:
    case “cover”:
    $custom = get_post_custom();
    echo the_post_thumbnail( ‘release-post-thumbnail’ );
    break;

    Reply
  40. morticya33 says

    September 5, 2010 at 5:34 pm

    Hi Shiba,

    Do you happen to know how to sort the column by ID or by some meta value added? 🙂

    Reply
    • ShibaShake says

      September 7, 2010 at 7:20 pm

      You can hook into the wp loop query request to do this. I usually hook into the ‘request’ filter hook. However, you must be careful with this because it will get run every time the WP loop (i.e., the wp function) gets called. Put in tight conditionals so that your orderby property only gets applied on the relevant pages.

      Reply
  41. Pierre says

    September 2, 2010 at 1:00 pm

    Hi Shibashake,

    is there’s a way to remove the integrated “categories” column to add the same one (categories) but with categories ordered by hierarchy (respecting the tree of categories) ?

    And, if yes, how to do that ?

    TIA.

    Amicably,

    Pierre.

    Reply
    • ShibaShake says

      September 4, 2010 at 3:21 pm

      To remove a column, in add_new_gallery_columns you would just

      unset($gallery_columns['categories']);
      

      Then you would add your own column –

      $gallery_columns['my_super_categories'] = __('Categories');
      

      Finally in the manage_gallery_columns you would add your own category tree rendering function –

      ...
      		switch ($column_name) {
      		case 'my_super_categories':
      			// render category tree
                              break;
      ...
      
      Reply
      • Pierre says

        September 6, 2010 at 7:34 am

        Thanks !!!

        Everything is cool now 🙂 You’re the one !!

        Thanks again Shibashake.

        Amicably,

        Pierre.

        Reply
  42. Pierre says

    August 1, 2010 at 5:23 am

    Hi Shibashake,

    i’m really new in the discovery of Custom types and this is second time i found your website as a REALLY good ressource 🙂 !
    You help me to found what i was searching for.

    So, with this comment, i wished to thank you :).

    PS. Do you know a way to add our custom(s) column(s) in a particular position ?

    Amicably,

    Pierre.

    Reply
    • ShibaShake says

      August 1, 2010 at 8:45 pm

      Do you know a way to add our custom(s) column(s) in a particular position

      You will need to insert it at exactly that location in the array. I usually just create a new array, but you can also use php array operations e.g. array_splice, array_merge, array_push to achieve an element insert.

      Reply
      • Maurizio says

        September 28, 2010 at 2:11 am

        array_splice doesn’t work with associative arrays. You can add your custom column at a chosen position defining the key before one you want your custom column to appear. For instance, if you want to add the custom column ‘Status’ before ‘column author’ you can do like this:

        your_filter_function($columns) {
        $insert_before = ‘author’;
        foreach ($posts_columns as $key => $val) {
        if ($key == $insert_before) {
        $new_columns[‘status’] = ‘Status’;
        $new_columns[$key] = $val;
        } else {
        $new_columns[$key] = $val;
        }
        }
        return($new_columns);
        }

        Reply
  43. alex says

    July 6, 2010 at 4:35 pm

    Is there a way to create a filter like in the edit posts category filter?

    For example a filter by a custom field?

    Thanks a lot, your lasts post are amazing!

    Reply
    • ShibaShake says

      July 8, 2010 at 10:34 am

      Hello Alex,
      So you want to create a filter for each of your custom fields?

      I would look into adding the apply_filters command and pass in the value(s) you want to modify. For example, if I want to modify the num_images value I could do the following –

      ...
      	case 'images':
      		// Get number of images in gallery
      		$num_images = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM $wpdb->posts WHERE post_parent = {$id};"));
                      $num_images = apply_filters('shiba_num_images_filter', $num_images);
      		echo $num_images; 
      		break;
      ...
      // add filter function
      add_filter('shiba_num_images_filter', 'my_filter_function');
      
      Reply
  44. Lane says

    June 24, 2010 at 7:25 pm

    You could even grab the first thumbnail and add that as column. Great posts! Where do I donate?

    Reply
    • ShibaShake says

      June 25, 2010 at 1:28 pm

      Thanks Lane. In terms of donation, just link to us when appropriate and that would be more than enough. 🙂

      Reply
    • Noe Ruiz says

      July 29, 2010 at 8:54 am

      Ahh, this is exactly what I’m trying to accomplish. How do you apply an image to the custom_columns function? I have a custom field value as the image url, I just need to pass that into the custom_columns function to display it on the cpt’s edit page. The search continues!

      Reply
      • ShibaShake says

        July 29, 2010 at 9:05 am

        Just do somethiing like –

        case 'my_image_field' :
        echo "<img src='{$my_image_url}' width='100' height='100'/>";
        break;
        
        Reply
        • Noe Ruiz says

          July 29, 2010 at 9:33 am

          Thank you Shiba for such a quick response. I’m still trying to figure this out.
          In place of $my_image_url how would I attach the custom field of “tuticon” to it?
          Basically want an image in place of the tutorial icon file names.

          Reply
        • Noe Ruiz says

          July 29, 2010 at 12:03 pm

          I must be writing this completely wrong. Echoing out the custom field might not be the way to do this? I apologize for my lack of php knowledge, such a noob I know. I greatly appreciate your help!!

          	case 'my_image_field':
          		$my_image_field="thumbnail";
          		echo "<img src=\"ID, $my_image_field, true); ?>\" />";
          		break;
          
          Reply
        • Noe Ruiz says

          July 29, 2010 at 1:31 pm

          Thank you for your help Shibashake, sorry for all comments. The following solved my problem.

          echo 'ID, $my_image, true).'" />';
          Reply
          • ShibaShake says

            July 29, 2010 at 8:42 pm

            Glad it worked out Ruiz. I think some of the php got lost so my guess is you used wp_get_attachment_image?

            < ?php 
            echo wp_get_attachment_image( $attachment_id, $size, $icon ); 
            ?> 
            

            Is that right? I will update your comment if that is the case. Thanks.

          • Freddie says

            September 25, 2010 at 5:20 pm

            So what was your final answer to showing images from posts? I’ve been searching how to do this for days. I would love to see your final code!

Leave a Reply to ShibaShake Cancel reply

Your email address will not be published.

Recent Posts

  • Screen-shot of mobile responsive Poll Daddy object, where text floats properly to the right of radio buttons.How to Make Poll Daddy Objects Mobile Responsive
  • Screen-shot of blog post with no page border (flowing design).Genesis Skins 1.5
  • Screen-shot of the media manager Create-Gallery screen, while doing a post search.Shiba Media Library 3.7
  • Screenshot of the Edit Gallery screen after we hit the Create Gallery button.How to Expand the WordPress Media Manager Interface
  • Blonde girl looking through and holding a circular picture frame.Shiba Gallery 4.3
  • Close-up of beautiful blonde holding a square picture frame.Google Authorship - Good or Bad for Search Traffic?
  • Shiba Widgets 2.0
  • Media Temple screenshot of editing my sub-domain DNS entry.Using CDN Cnames with w3tc and MultiSite
  • Shiba Skins WordPress ThemeShiba Skins WordPress Theme
  • How to add the Media Manager Menu to the Theme Preview InterfaceHow to Add the Media Manager Menu to the Theme Preview Interface

Recent Comments

  • WordPress Search Widget – How to Style It (55)
    • TelFiRE
      - How do you style the "X" that shows up when you start typing?
  • Update custom inputs with the proper data using Javascript.Expand the WordPress Quick Edit Menu (56)
    • Francine Carrel
      - This is a very long time away from your original comment, but did you ever work it out? I am stuck on the exact same thing ...
  • WordPress Excerpt – How to Style It (36)
    • James
      - Great post. I really need some help. I have set border lines around my excerpts on my blog page/post page. The problem is ...
  • Add Custom Taxonomy Tags to Your WordPress Permalinks (123)
    • Darshan Saroya
      - Update permalinks. Go to settings > permalink and just save it.
    • Darshan Saroya
      - I want to access two different types of taxonomies like city and room, how can I access it via wp permalink?
  • How to Selectively Load Plugins for Specific Pages (6)
    • cla
      - Perfect! But at first I was misled, I thought the path / wordpress-theme / was an your alias of / theme .. and nothing happened.. ...
    • Aeros
      - Hi, I have tried your way. My problem is i'm using boilerplate to most of my plugins. When i tried to include the plugin ...
  • Write a Plugin for WordPress Multi-Site (44)
    • An Quach
      - I always use single site because it's easy for me to managed. When I need another worpdress on subdomain or subfolder, I ...
  • Screen-shot of mobile responsive Poll Daddy object, where text floats properly to the right of radio buttons.How to Make Poll Daddy Objects Mobile Responsive (3)
    • Nick
      - Thanks for this, took a while for me to find your post but it's the only answer online!
  • WordPress Theme Customizer Javascript Interface (21)
    • MailOptin Plugin
      - Excellent overview of the WordPress JS customizer API.Learned a ton from this post.

Copyright © 2019 · Genesis Skins by ShibaShake · Terms of Service · Privacy Policy ·