• Resolved Vic Drover

    (@vdrover)


    I found the snippet in the FAQs to customize the image based on post type. The Events Calendar is essentially a custom post type, and I’ve modified the snippett successfully for ‘tribe_events’ === $post->post_type.

    I’d also like to modify the snippet for images based on category. In this case, event categories inside The Events Calendar.

    I had hoped these categories were simply wordpress categories, but it seems not as modifying your category example with the slugs from the Events Calendar categories did not work.

    If you have a suggestion, please send.

Viewing 1 replies (of 1 total)
  • Plugin Author Jan-Willem

    (@janwoostendorp)

    Hello Vic,

    That certainly is possible, we just need to to use a different taxonomy function (custom categories are called taxonomies).

    I’m not familiar with Event Calendar, so I don’t know how that taxonomy is called, But if there is a edit page in the admin you should be able to find it in the url: example:

    example.com/wp/wp-admin/edit-tags.php?taxonomy=EVENT_CALENDAR_TAX

    Given that, the following snippet should work:

    add_filter( 'dfi_thumbnail_id', 'dfi_event_calendar', 10, 2 );	
    function dfi_event_calendar( $dfi_id, $post_id ) {
    	// This will trigger first, if multiple categories have been set.
    	if ( has_term( 'cats', 'REPLACE_WITH_TAXONOMY_NAME', $post_id ) ) {
    		return 7; // cats img id.
    	}
    	if ( has_term( 'dogs', 'REPLACE_WITH_TAXONOMY_NAME', $post_id ) ) {
    		return 8; // dogs img id.
    	}
    
    	return $dfi_id; // the original featured image id.
    }

    Let me know how it goes.

Viewing 1 replies (of 1 total)
  • The topic ‘custom image based on “event category”’ is closed to new replies.