I found a solution, but it seems rather cumbersome. I would think a cleaner solution would be possible using WP’s native thumbnail functions, but I can’t figure it out.
When I use the “tribe_event_featured_image” function, it replaces the images well wherever that function is loaded in the templates. However, I also use for example the Genesis Framework and their Responsive Slider plugin. The solution with the tribe function didn’t populate the slider with the featured image, as that was called with the “genesis_image” function (which uses and filters WP’s thumbnail function).
That’s why I think a function that deals with the native capabilities would be better too. But here’s the code that made it possible for me to display the organizer’s featured image as the event’s featured image if no featured image was set.
/** Define a default post thumbnail Genesis */
function default_event_image_fallback($output, $args) {
global $post;
if( $output || $args['size'] == 'full' && get_post_type() == 'tribe-events' )
return $output;
$post_id = tribe_get_organizer_id();
$image_src = wp_get_attachment_image_src( get_post_thumbnail_id( $post_id ), $size );
$thumbnail = $image_src[0];
switch($args['format']) {
case 'html' :
return '<img src="'.$thumbnail.'" class="attachment-'. $args['size'] .'" alt="'. get_the_title($post_id) .'" />';
break;
case 'url' :
return $thumbnail;
break;
default :
return $output;
break;
}
}
add_filter('genesis_get_image', 'default_event_image_fallback', 10, 2);
/** Define a default post thumbnail Events Calendar */
function set_default_event_featured_img( $featured_image, $post_id, $size, $image_src ) {
if ( ! $featured_image ) {
$post_id = tribe_get_organizer_id();
$image_src = wp_get_attachment_image_src( get_post_thumbnail_id( $post_id ), $size );
$featured_image = '';
//if link is not specifically excluded, then include <a>
if ( ! empty( $image_src ) && $link ) {
$featured_image .= '<div class="tribe-events-event-image"><a href="' . tribe_get_event_link() . '" title="' . get_the_title( $post_id ) . '"><img src="' . $image_src[0] . '" title="' . get_the_title( $post_id ) . '" /></a></div>';
} elseif ( ! empty( $image_src ) ) {
$featured_image .= '<div class="tribe-events-event-image"><img src="' . $image_src[0] . '" title="' . get_the_title( $post_id ) . '" /></div>';
}
return apply_filters( 'tribe_event_featured_image', $featured_image, $post_id, $size, $image_src );
}
else {
return $featured_image;
}
}
add_filter( 'tribe_event_featured_image', 'set_default_event_featured_img', 10, 4 );