• Resolved jetpackjack

    (@jetpackjack)


    Hi, I’m using Ajax Search Pro to return the post type [aiovg_videos] but the featured image isn’t showing in the gallery, yet there is an image added to the videos. How can I achieve this?

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

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

    (@wpvideogallery)

    Unfortunately, our current version doesn’t store images as featured images. But, this is already on our TODO lists. So, we will have this very soon.

    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 OLD 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 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 solved your issue!

    Thread Starter jetpackjack

    (@jetpackjack)

    Thanks for the reply. I added the code to the bottom of my themes functions.pho file and when I go to a video it now shows the option to ‘set featured image’. I can then choose an image which shows in the editor but as soon as I save it disappears. Any ideas on this?

    Thread Starter jetpackjack

    (@jetpackjack)

    Ignore that last message, looks to be working perfectly! thank you ??

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