Automatically get the logo and the featured image from parent post relation field. Just pay attention to post type (eg. “events”), logo (logo), featured image (_thumbnail_id) and post relation (post-relation) field keys.
PHP Code SnippetAfter installing a child theme, navigate to Appearance > Theme Editor > functions.php and paste at the bottom of the input.
function update_events_logo( $event ) { $post = $event->post;
// Check if it's a jobs post if ( $post->post_type->get_key() !== 'events' ) { return; }
// Get the related post ID from the post-relation field $relation_id = $post->get_field('post-relation')->get_value()[0] ?? null;
if ( $relation_id && is_numeric( $relation_id ) ) { // Get the logo attachment ID from the related post $logo_id = get_post_meta( $relation_id, 'logo', true );
if ( $logo_id && is_numeric( $logo_id ) ) { // Update the events post's logo with the attachment ID update_post_meta( $post->get_id(), 'logo', (int) $logo_id ); } } }
// Check if it's an events post if ( $post->post_type->get_key() !== 'events' ) { return; }
// Get the related post ID from the post-relation field $relation_id = $post->get_field('post-relation')->get_value()[0] ?? null;
if ( $relation_id && is_numeric( $relation_id ) ) { // Get the featured image attachment ID from the related post $thumbnail_id = get_post_meta( $relation_id, '_thumbnail_id', true );
if ( $thumbnail_id && is_numeric( $thumbnail_id ) ) { // Update the events post's featured image with the attachment ID update_post_meta( $post->get_id(), '_thumbnail_id', (int) $thumbnail_id ); } } }