Skip to content

Instantly share code, notes, and snippets.

@joshfeck
Created January 26, 2016 17:07
Show Gist options
  • Save joshfeck/da54b92ecf709341c26a to your computer and use it in GitHub Desktop.
Save joshfeck/da54b92ecf709341c26a to your computer and use it in GitHub Desktop.
From https://eventespresso.com/topic/posting-registration-url-to-facebook/#post-189425 Sync EE3 featured image from event to blog post
<?php
//* Please do NOT include the opening php tag, except of course if you're starting with a blank file
/* syncs EE3 event featured image to event's blog post */
add_action( 'action_hook_espresso_insert_event_success', 'my_ee3_event_image_function' );
add_action( 'action_hook_espresso_update_event_success', 'my_ee3_event_image_function' );
function my_ee3_event_image_function( $event_data ) {
global $wpdb;
if ( isset( $event_data['upload_image'] ) && ! empty( $event_data['upload_image'] ) ){
$image_url = $event_data['upload_image'];
$image_url = preg_replace( '/-\\d+[Xx]\\d+\\./', '.', $image_url );
$attachment = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE guid='%s';", $image_url ) );
if ( ! empty( $attachment ) ) {
$attach_id = $attachment[0];
$post_id = $event_data['post_id'];
set_post_thumbnail( $post_id, $attach_id );
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment