Created
January 26, 2016 17:07
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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