• Resolved samii

    (@samii)


    hello,

    Thanks for the great work on this plugin, I am wondering if it is possible to set the banner image as a feature image. I got it working on admin by adding
    add_post_type_support('event_listing', 'thumbnail');

    but is it possible to set banner image on upload …

    Cheers

Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Author Ashok Dudhat

    (@ashokdudhat)

    Hi Samii,

    Yes, You can able to set feature image for this plugin with new field but you need to customise little bit.

    For the banner case, if you allow only one banner instead of multiple then it make sense for feature image.

    Also you can try same like woo commerce provide product gallery, similar multiple banners.

    In future version, we will add this things.

    Hope it will help you.

    Thanks

    Thread Starter samii

    (@samii)

    many thanks Ashok, I was thinking to make the banner image or (maybe first uploaded image in case multiple image upload …) to be set as featured image.

    I was able to get it working by adding set_post_thumbnail($this->event_id, $attachment_id); to wp-event-manager-form-submit-event.php but was hoping to find a cleaner way to do it without changing the plugin code …

    Hi Samii,

    I was also struggling to solve the same situation to set the first image as a featured image and I was able to successfully do it by adding following code in my theme’s functions.php file. Here is the code that will set every 1st uploaded image as a featured image of the post when it is PUBLISHED:

    //Auto Set 1st Image of Event as a Featured Image 
    function auto_add_featured_image_events($new_status, $old_status, $post) {
    	global $post;
    	
    	if ($post->post_type == 'event_listing') {
    	
    		$data = get_post_meta( $post->ID, '_event_banner', false);
    	    	foreach ($data as $key=>$image) {
    		
    		// set the image url
    		$image_url = $image[0];
    		
    		// store the image ID in a var
    		$image_id = attachment_url_to_postid($image_url);
    		
    		if($new_status == 'publish') {
    		
    			//Update the 1st Image of event as featured Image
    			update_post_meta( $post->ID, '_thumbnail_id', $image_id );
    			}
    		}
    	}
    }
    add_action( 'transition_post_status', 'auto_add_featured_image_events', 1, 3);
    Plugin Author Ashok Dudhat

    (@ashokdudhat)

    Hi,

    @atharalikhichi, Your solution is right one ??

    @samii you can use above solution as given by Atharlikhichi.

    [ Signature moderated ]

    • This reply was modified 7 years, 6 months ago by Ashok Dudhat.
    • This reply was modified 7 years, 1 month ago by Jan Dembowski.

    Thanks

    Thread Starter samii

    (@samii)

    Thank You @ashokdudhat,
    Many Thanks @atharalikhichi, your code gave me a good kick start ?? but I wanted to work a little different, finally I got it working on adding/updating event like bellow.

    Appreciate any feedback, I am new to WordPress

    function set_event_featured_image($post_id) {
    	if(!is_admin()) {
    	if (get_post_type($post_id) == 'event_listing') {
    	$data = get_post_meta($post_id, '_event_banner', false);
    	$image_url = $data[0];
    	$image_id = attachment_url_to_postid($image_url);
    	update_post_meta($post_id, '_thumbnail_id', $image_id);
    		}
    	}
    }
    add_action('event_manager_update_event_data', 'set_event_featured_image');
    • This reply was modified 7 years, 6 months ago by samii.
    Plugin Author Ashok Dudhat

    (@ashokdudhat)

    Dear Samii,

    As you provide solution that more secure than previous one, i mean it will only update featured image settings for the event_listing custom post type and not for other custom post type because you have bound hook event_manager_update_event_data so when any new event update or adding then this will fire.

    Thanks

    Thread Starter samii

    (@samii)

    Many thanks again ??

    complete code with thumbnail support for event_listing

    /* Add featured image to post type 'event_listing */
    add_post_type_support('event_listing', 'thumbnail');
    
    /* Get uploaded image from metadata and set _thumbnail id */
    function set_event_featured_image($post_id) {
    	if(!is_admin()) {
    	if (get_post_type($post_id) == 'event_listing') {
    	$data = get_post_meta($post_id, '_event_banner', false);
    	$image_url = $data[0];
    	$image_id = attachment_url_to_postid($image_url);
    	update_post_meta($post_id, '_thumbnail_id', $image_id);
            /* 
    	-- This will also work ... comment line above to use --
    	set_post_thumbnail($post_id, $image_id);
    	---- 
    	*/
    		}
    	}
    }
    /* adding action hook to event_manager_update_event_data */
    add_action('event_manager_update_event_data', 'set_event_featured_image');
    • This reply was modified 7 years, 6 months ago by samii.
    Plugin Author Ashok Dudhat

    (@ashokdudhat)

    Hi Samii,

    Thanks for final update ??

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Enable Featured Image’ is closed to new replies.