Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm trying to create a custom column for my custom post type and I'm having no luck. Below is the code I'm using, I have a similar code that pulls the featured thumbnail and that works for all post types, but this column will only show up on the custom post type. Any help would be appreciated.

add_filter("manage_Featured_columns", "edit_Featured_columns" );
add_action("manage_Featured_column", "custom_Featured_columns");
function custom_Featured_columns($Featured_column) {
    global $post;
    switch ($Featured_column) {
        case "redirect_url":
                if(get_post_meta($post->ID, 'redirect_url', true) !='') {
                    echo get_post_meta($post->ID, 'redirect_url', true);
                } else { echo '-'; }

} }

That is the code I have so far, but it's not showing up on the Featured custom post type. The name I'm using in my custom post type is: register_post_type( 'Featured',

Thanks

share|improve this question
add comment

1 Answer 1

up vote 0 down vote accepted

You're missing a couple of things

  1. hook for registering custom column is manage_edit-{$post_type}_columns thus you have to use manage_edit-Featured_columns on line one (instead of yours manage_Featured_columns ).
  2. hook for getting custom column content is manage_{$post_type}_posts_custom_column thus you should use this code in second add_action call: manage_Featured_posts_custom_column
  3. You have to add define columns which are about to appear in edit_Featured_columns function (first add_action call).

This way:

function edit_Featured_columns( $columns ) {
        return array(
            'cb' => '<input type="checkbox" />',
            'title' => __( 'Title' ),
            'redirect_url' => __( 'Redirect url' ),
            'date' => __( 'Date' )
        );
    }

That's all. Your custom_Featured_columns function seems to be ok.

Here's a good tutorial on this topic: http://justintadlock.com/archives/2011/06/27/custom-columns-for-custom-post-types

share|improve this answer
    
Worked, thanks for your help! –  user27274 Feb 12 '13 at 6:40
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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