Last active
March 28, 2016 11:29
-
-
Save davidperezgar/3c46a6486109042657c1 to your computer and use it in GitHub Desktop.
Manage Admin columns WordPress
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** 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