Documentation - Actions / Filters - Filter – Sort Interface – Post Types Items Custom Thumbnails

Share on FacebookTweet about this on TwitterShare on Google+Share on LinkedInPrint this page

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:

1function  theme_apto_reorder_item_thumbnail($image_html, $post_ID)
2    {
3        //let's use a custom field called "custom_image" which contain the media we need to show for this
4        $image_url = get_post_meta($post_ID, 'custom_image', TRUE);
5        if($image_url != '')
6            $image_html = '<img src="'. $image_url .'" width="64" alt="" />';
7 
8        return $image_html;
9    }
10add_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:

1function  theme_apto_reorder_item_thumbnail($image_html, $post_ID)
2    {
3        $image_id = get_post_meta($post_ID, 'custom_image', TRUE);       
4        $image_data = wp_get_attachment_image_src($image_id, 'thumbnail');
5        $image_url = $image_data[0];
6         
7        if($image_url != '')
8            $image_html = '<img src="'. $image_url .'" width="64" alt="" />';
9  
10        return $image_html;
11    }
12add_filter('apto/reorder_item_thumbnail', 'theme_apto_reorder_item_thumbnail', 10, 2);

The following code works with the WP E-Commerce product gallery :

1function  theme_apto_reorder_item_thumbnail($image_html, $post_ID)
2    {
3        //let's use a custom field called "custom_image" which contain the media we need to show for this
4        $image_id = get_post_meta($post_ID, '_wpsc_product_gallery', TRUE);       
5        $image_data = wp_get_attachment_image_src($image_id, 'thumbnail');
6        $image_url = $image_data[0];
7         
8        if($image_url != '')
9            $image_html = '<img src="'. $image_url .'" width="64" alt="" />';
10  
11        return $image_html;
12    }
13add_filter('apto/reorder_item_thumbnail', 'theme_apto_reorder_item_thumbnail', 10, 2);

*This code should be used within the theme or a custom plugin.