Skip to content

Instantly share code, notes, and snippets.

@davidperezgar
Last active March 28, 2016 11:29
Show Gist options
  • Save davidperezgar/3c46a6486109042657c1 to your computer and use it in GitHub Desktop.
Save davidperezgar/3c46a6486109042657c1 to your computer and use it in GitHub Desktop.
Manage Admin columns WordPress
/** Add columns **/
// Add to admin_init function
add_filter('manage_edit-productos_columns', 'add_new_productos_columns');
function add_new_productos_columns($columns) {
$columns['cb'] = '<input type="checkbox" />';
$columns['title'] = 'Producto';
$columns['prod_ref'] = 'Referencia';
$columns['prod_precio'] = 'Precio';
$columns['image'] = 'Miniatura';
return $columns;
}
// Add to admin_init function
add_action('manage_productos_posts_custom_column', 'manage_productos_columns', 10, 2);
function manage_productos_columns($column_name, $id) {
global $wpdb;
$custom = get_post_custom($id);
if(isset($custom["prod_ref"][0]) ) $prod_ref = $custom["prod_ref"][0]; else $prod_ref ='';
if(isset($custom["prod_precio"][0]) ) $prod_precio = $custom["prod_precio"][0]; else $prod_precio ="";
switch ($column_name) {
case 'prod_ref':
echo $prod_ref;
break;
case 'prod_precio':
echo $prod_precio;
break;
case 'image':
echo get_the_post_thumbnail( $id, array(120,120) );
break;
default:
break;
} // end switch
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment