Custom field columns in wordpress admin area
-
Hi guys,
On the posts admin screen wordpress has some default columns such as ‘author’, ‘tags’, and ‘categories’. I have customised mine slightly so there is a column which displays the values of my custom field ‘price’. This makes my life easier as i run a shopping site where each product is a post. .
I have another custom field named ‘product image’, where the value is a link to a picture of the product. Does anyone know if there is a way to have wordpress echo this image in the column, so i can visibly see each product in the list?
Here is the code that currently shows the price value. The first part registers the new column and the second part grabs the custom field price value. If i just change it to echo the product image i just see the link text, where as i actually want it to visibly show the image. Any help with this is greatly appreciated. Thanks
<?php // Register the column function price_column_register( $columns ) { $columns['price'] = __( 'Price', 'my-plugin' ); return $columns; } add_filter( 'manage_edit-post_columns', 'price_column_register' ); // Display the column content function price_column_display( $column_name, $post_id ) { if ( 'price' != $column_name ) return; $price = get_post_meta($post_id, 'price', true); if ( !$price ) $price = '<em>' . __( 'undefined', 'my-plugin' ) . '</em>'; echo $price; } add_action( 'manage_posts_custom_column', 'price_column_display', 10, 2 ); ?>
- The topic ‘Custom field columns in wordpress admin area’ is closed to new replies.