• Resolved tsarr

    (@tsarr)


    The image which we upload in the section doesn’t consider a featured image. It is bugging me because when someone shares a link the image which shows is my site’s logo. Sometimes I have to manually upload images using AISEO plugins.
    Is there any way I could add the feature so I don’t have to manually add an image?
    Thanks

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Contributor wpvideogallery

    (@wpvideogallery)

    Unfortunately, our current version doesn’t store images uploaded through our video form as featured images. But, this is already on our TODO lists. So, I promise that we will have this very soon in the future.

    As a quick solution, we have prepared a patch for you. Kindly try adding the following code to the bottom of your theme’s functions.php file.

    function aiovg_custom_init() {
        add_post_type_support( 'aiovg_videos', 'thumbnail' );
    }
    add_action( 'init', 'aiovg_custom_init', 11 );
    
    // Works on existing video posts
    function aiovg_set_featured_images() {
        if ( false == get_option( 'aiovg_featured_images_inserted' ) ) {
            add_option( 'aiovg_featured_images_inserted', 1 );
    
            $items = get_posts( array( 'post_type' => 'aiovg_videos', 'post_status' => 'any', 'numberposts' => -1, 'fields' => 'ids' ) );
               
            if ( count( $items ) ) {
                foreach ( $items as $item ) {
                    $image_id = get_post_meta( $item->ID, 'image_id', true );
                    if ( (int) $image_id > 0 ) {
                        set_post_thumbnail( $item->ID, $image_id );
                    }              
                }
            }
        }
    }
    add_action( 'init', 'aiovg_set_featured_images' );
    
    // Works on NEW video posts
    function aiovg_custom_save_featured_image( $post_id, $post ) {  
        if ( ! isset( $_POST['post_type'] ) ) {
            return $post_id;
        }
    
        // Check this is the "aiovg_videos" custom post type
        if ( 'aiovg_videos' != $post->post_type ) {
            return $post_id;
        }
       
        // If this is an autosave, our form has not been submitted, so we don't want to do anything
        if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
            return $post_id;
        }
    
        // Check if "aiovg_video_sources_nonce" nonce is set
        if ( isset( $_POST['aiovg_video_sources_nonce'] ) ) {      
            // Verify that the nonce is valid
            if ( wp_verify_nonce( $_POST['aiovg_video_sources_nonce'], 'aiovg_save_video_sources' ) ) {
                $image_id = get_post_meta( $post_id, 'image_id', true );
                if ( (int) $image_id > 0 ) {
                    set_post_thumbnail( $post_id, $image_id );
                }
            }
        }
    
        return $post_id;
    }
    add_action( 'save_post', 'aiovg_custom_save_featured_image', 99, 2 );

    Hope this helped you!

    Thread Starter tsarr

    (@tsarr)

    Not working.

    Plugin Contributor wpvideogallery

    (@wpvideogallery)

    Kindly submit a ticket here https://plugins360.com/support/ with this post URL. So, we can get some details about your website privately to further investigate the issue.

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