pay attention to post type (eg. “events”), logo (logo), featured image (_thumbnail_id) and post relation (post-relation) field keys.

changelog

Live Example

[own_shortcode1] add_action( 'voxel/app-events/post-types/events/post:submitted', 'update_events_featured_image' ); add_action( 'voxel/app-events/post-types/events/post:updated', 'update_events_featured_image' ); function update_events_featured_image( $event ) { $post = $event->post; // 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 ); } } }

PHP

add_action( 'voxel/app-events/post-types/events/post:submitted', 'update_events_featured_image' );
add_action( 'voxel/app-events/post-types/events/post:updated', 'update_events_featured_image' );
function update_events_featured_image( $event ) {
$post = $event->post;


// 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 );
}
}
}

Automatically get featured Image from related post

The Mission

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut elit tellus, luctus nec ullamcorper mattis, pulvinar dapibus leo. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut elit tellus, luctus nec ullamcorper mattis, pulvinar dapibus leo.

There are no results matching your search

AI Assistant