Filter – Sort Interface – Post Types Items Custom Thumbnails
This filter will help to change the default thumbnail (either featured image or no image) for a custom post type item within the re-order interface.
apto/reorder_item_thumbnail
Examples:
The following code will return a custom image instead the default thumbnail:
function theme_apto_reorder_item_thumbnail($image_html, $post_ID) { //let's use a custom field called "custom_image" which contain the media we need to show for this $image_url = get_post_meta($post_ID, 'custom_image', TRUE); if($image_url != '') $image_html = '<img src="'. $image_url .'" width="64" alt="" />'; return $image_html; } add_filter('apto/reorder_item_thumbnail', 'theme_apto_reorder_item_thumbnail', 10, 2);
In case the custom_image meta data is not an image url but an attachment, this code can be used instead:
function theme_apto_reorder_item_thumbnail($image_html, $post_ID) { $image_id = get_post_meta($post_ID, 'custom_image', TRUE); $image_data = wp_get_attachment_image_src($image_id, 'thumbnail'); $image_url = $image_data[0]; if($image_url != '') $image_html = '<img src="'. $image_url .'" width="64" alt="" />'; return $image_html; } add_filter('apto/reorder_item_thumbnail', 'theme_apto_reorder_item_thumbnail', 10, 2);
The following code works with the WP E-Commerce product gallery :
function theme_apto_reorder_item_thumbnail($image_html, $post_ID) { //let's use a custom field called "custom_image" which contain the media we need to show for this $image_id = get_post_meta($post_ID, '_wpsc_product_gallery', TRUE); $image_data = wp_get_attachment_image_src($image_id, 'thumbnail'); $image_url = $image_data[0]; if($image_url != '') $image_html = '<img src="'. $image_url .'" width="64" alt="" />'; return $image_html; } add_filter('apto/reorder_item_thumbnail', 'theme_apto_reorder_item_thumbnail', 10, 2);
*This code should be used within the theme or a custom plugin.
Thank you Dan for your speedy reply with the link to this post.
I put the code into my theme’s function.php, changed the ‘custom-image’ to the name of my custom image field, but no images in the sortable lists. Not with thumbnails activated nor without. Where did I go wrong?
Thank you!
Most probably there’s a html error in your code or the filter is never called due to wrong placement. If you can’t figure out, please get in touch with us through support and someone will check into it for you.
Thank you
This goes into the theme’s function.php file, correct? I tried it with Dandelion theme and it did not work for me; I changed ‘custom-image’ to ‘portfolio-image’ but the plugin kept trying to pull from the featured image; it had no affect. Is there anything we can do within the plugin’s coding itself to change this to a different class image?
Yes this goes into theme function file. If the plugin does not display the required image (portfolio-image) this means the custom field is either empty or does not exists, i suggest to check on it again.