Skip to content

Instantly share code, notes, and snippets.

@MrJoshFisher
Created February 28, 2023 10:02
Show Gist options
  • Save MrJoshFisher/f5a1528d82b8a01423e5a23458529f2c to your computer and use it in GitHub Desktop.
Save MrJoshFisher/f5a1528d82b8a01423e5a23458529f2c to your computer and use it in GitHub Desktop.
[Add custom admin column] #wordpress #php
add_filter('manage_product_posts_columns' ,'custom_post_type_columns');
function custom_post_type_columns($columns){
// Remove Author and Comments from Columns and Add custom column 1, custom column 2 and Post Id
$columns['badge'] = 'Badge';
return $columns;
}
add_action( 'manage_product_posts_custom_column' , 'fill_custom_post_type_columns', 10, 2 );
function fill_custom_post_type_columns( $column, $post_id ) {
// Fill in the columns with meta box info associated with each post
switch ( $column ) {
case 'badge' :
switch(get_post_meta($post_id, 'badge')[0]) {
case 'poa':
echo '<span style="color:#f42494">POA</span>';
break;
case 'tbc':
echo '<span style="color:#0024ba">TBC</span>';
break;
case 'new':
echo '<span style="color:#02b801">NEW</span>';
break;
case 'sold':
echo '<span style="color:#fd2100">SOLD</span>';
break;
case 'hold':
echo '<span style="color:#017bc8">HOLD</span>';
break;
}
break;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment