I have a few custom thumbnail sizes and obviously one of them is used in the set_post_thumbnail_size, what directly affects the interface in the admin area.
What I’m looking to do is to intercept which admin page (for post-type) I’m in and set a different size in the above function, so basically I’d like to have that:
function setup_the_theme() {
add_theme_support( 'post-thumbnails' );
if ($post_type == 'type_A'){
set_post_thumbnail_size( 298, 167, true ); //portrait
} else {
set_post_thumbnail_size( 192, 108, true ); //landscape
}
add_image_size( 'top_articles', 298, 167, true ); //portrait
add_image_size( 'article_thumb', 203, 114, true ); //portrait
add_image_size( 'featured_articles', 60, 200, true ); //landscape
}
add_action( 'after_setup_theme', 'setup_the_theme' );
I suspect its too early in the cycle to know which post type i’m editing.
5 s
Simpler way to figure out the post type of the item (which you are editing) and uploading media to:
$type = get_post_type($_REQUEST['post_id']);
As has been noted, the media upload iframe that is shown in the lightbox overlay when you try to upload something doesn’t indicate the parent post that new upload will be attached to. But the $_REQUEST
is still active from the edit window, and still contains the post_id of the item you’re editing – so just query the type for that id…
You can use this technique in various hooks and filters – I’ve used the intermediate_image_sizes
filter for image processing before, but not for this particular problem, but it should work there too…