0

I know know how to get all the custom fields from a custom post type, that's easy.

However, when I create a custom post type, it displays a beautiful page automatically in the administration part of Wordpress, but with only "title" and "date" as fields:

no custom fields

If I want to add a field called "size" for the chimpmonks so that it displays in that administration screen, what should I do?

0

You need an action called manage_$post_type_posts_custom_column. This will allow you to add columns to your custom posts page. To be more precise, you need a filter to generate the column and an action to fill it with content. In your case something like this (untested):

add_filter( 'manage_chimpmunks_posts_columns', 'set_custom_size_column' );
add_action( 'manage_chimpmunks_posts_custom_column' , 'fill_custom_size_column', 10, 2 );

function set_custom_size_column($columns) {
    $columns['size'] = __( 'Size', 'your_text_domain' );
    return $columns;
}

function fill_custom_size_column( $post_id ) {
    $terms = get_the_term_list( $post_id , 'size' , '' , ',' , '' );
    if ( is_string( $terms ) )
         echo $terms;
    else
         echo __( 'No size', 'your_text_domain' );
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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