1

I am trying to add a column to my Custom Post Type Admin Screen that will show the author's email address. Any advice for novice coders (such as myself) that describe how to accomplish this? I've come up empty in searching for a tutorial specific to what I'm trying to do.

Thanks, Sean

3

1 Answer 1

1

May be you can try this:

add_filter('manage_edit-movie_columns', 'custom_add_new_columns');
function custom_add_new_columns( $columns ){
    $columns['author_email'] = 'Email';
    return $columns;
}
add_action('manage_movie_posts_custom_column', 'custom_manage_new_columns', 10, 2);
function custom_manage_new_columns( $column_name, $id ){
    if ('author_email'==$column_name){
     $current_item = get_post($id);
     $author_id = $current_item->post_author;
     $author_email = get_the_author_meta( 'user_email', $author_id);
     echo '<a href="mailto:'.$author_email.'">'.$author_email.'</a>';
    }
}

Here, I have used custom post type movie. You need to replace movie word in hooks with your custom post type name.

For example, if your CPT is flower, hooks should be manage_edit-flower_columns and manage_flower_posts_custom_column.

First function adds heading of columns in the table. Second function adds content of the column according to the current post.

1
  • Perfect! This is exactly what I was looking for. Commented Aug 25, 2014 at 19:20

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.