• Resolved projecta

    (@projecta)


    We have extended Tribe Events with a custom image field in Pods. This works for single day/time events, but if the event is recurring (a series), the image doesn’t save.

    The page I need help with: [log in to see the link]

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Scott Kingsley Clark

    (@sc0ttkclark)

    This is a known issue. Unfortunately because of the latest (awesome) updates in TEC and Events Calendar Pro — extending those objects is going to require a much more integrated approach to make that happen. At this point, series just aren’t supported without custom coding.

    Plugin Support Paul Clark

    (@pdclark)

    I don’t have an active license for TEC Pro with which to test, but looking at some recent code for recurring events, here are some approaches which might work for accessing an image field associated with a recurring Event’s source event:

    Looking at events-calendar-pro/src/Tribe/Recurrence/Event_Query.php function include_parent_event(), it looks like the ID of the starting event is stored in the WordPress core field post_parent, in wp_posts for a recurring event.

    So, a function like below would take $post->post_parent from the currently viewed recurring event, and would return an image tag (display) from a Pods field called an_image_field:

    <?php
    function get_parent_event_image_field( $parent_event_id ) {
    	return pods( 'tribe_events', $parent_event_id )->display( 'an_image_field' );
    }

    In a Pods template context, the magic tag {@post_parent,get_parent_event_image_field} would run that function and the current object’s post parent — as noted by the comma in between the field name and the custom function name.

    A similar result can be achieved with the WordPress core filter https://developer.wordpress.org/reference/hooks/get_meta_type_metadata/ by setting a custom meta key to return the URL of the associated image, either from the current Event, or the Parent Event if it is recurring.

    In this example, the Pods image field is an_image_field, which stores an attachment ID. This filter will return the URL to the image from the meta key an_image_or_parent_image. These two quoted keys need to be different. The image size is large.

    <?php
    add_filter(
    	'get_post_metadata',
    	function( $value, $event_id, $meta_key, $single, $meta_type ) {
    		if (
    			'an_image_or_parent_image' !== $meta_key
    			|| 'tribe_events' !== get_post_type( $event_id )
    		) {
    			return $value;
    		}
    		$event = get_post( $event_id );
    		if ( ! empty( $event->post_parent ) ) {
    			// If the event parent is not 0, change the event ID to the parent.
    			$event_id = $event->post_parent;
    		}
    		// Get the ID of the attachment on the top-level event.
    		$image_id = get_post_meta( $event_id, 'an_image_field', true );
    		if ( ! empty( $image_id ) ) {
    			return wp_get_attachment_image_src( $image_id, 'large' );
    		}
    		// If nothing was found, return null.
    		return $value;
    	},
    	20,
    	5
    );

    To use the above,

    echo get_post_meta( get_the_ID(), 'an_image_or_parent_image', true ); 

    …would output the URL for the custom image starting from the current event ID.

    Thread Starter projecta

    (@projecta)

    Thank you for the detailed response! Currently I worked around this by using a URL field for the image, and changed my template to use the URL within an img tag, but I will try this method.

Viewing 3 replies - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.