0

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

1 Answer 1

0

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

0

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.