Skip to content

Instantly share code, notes, and snippets.

@sarfarazansari
Last active February 14, 2022 04:25
Show Gist options
  • Save sarfarazansari/2b0f16bb80b827a91aeb8f955d957b53 to your computer and use it in GitHub Desktop.
Save sarfarazansari/2b0f16bb80b827a91aeb8f955d957b53 to your computer and use it in GitHub Desktop.
add custom column in wp admin for custom post type
// Add the custom columns to the rezept post type:
add_filter( 'manage_rezept_posts_columns', 'set_custom_edit_rezept_columns' );
function set_custom_edit_rezept_columns($columns) {
unset($columns['date']);
return array_merge ( $columns, array (
'name' => __('Vor- & Nachname'),
'email' => __('E-mail Adresse'),
'group_of_people' => __('Personengruppe'),
'activation_date' => __('Erstellungsdatum'),
'recipe_status' => __('Status'),
'date' => __('Veröffentlicht')
));
return $columns;
}
// Add the data to the custom columns for the book post type:
add_action( 'manage_rezept_posts_custom_column' , 'custom_rezept_column', 10, 2 );
function custom_rezept_column( $column, $post_id ) {
switch ( $column ) {
case 'recipe_status' :
echo get_post_meta( $post_id, 'recipe_status', true);
break;
case 'name':
echo get_post_meta( $post_id, 'name', true);
break;
case 'email':
echo get_post_meta( $post_id, 'email', true);
break;
case 'group_of_people':
echo get_post_meta( $post_id, 'group_of_people', true);
break;
case 'activation_date':
echo get_the_modified_date('l jS \of F Y h:i:s A', $post_id);
break;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment