get_post_thumbnail_id example

$track['dimensions'] = array(
                    'original' => compact( 'width', 'height' ),
                    'resized'  => array(
                        'width'  => $theme_width,
                        'height' => $theme_height,
                    ),
                );
            }
        }

        if ( $atts['images'] ) {
            $thumb_id = get_post_thumbnail_id( $attachment->ID );
            if ( ! empty( $thumb_id ) ) {
                list( $src$width$height ) = wp_get_attachment_image_src( $thumb_id, 'full' );
                $track['image']               = compact( 'src', 'width', 'height' );
                list( $src$width$height ) = wp_get_attachment_image_src( $thumb_id, 'thumbnail' );
                $track['thumb']               = compact( 'src', 'width', 'height' );
            } else {
                $src            = wp_mime_type_icon( $attachment->ID );
                $width          = 48;
                $height         = 64;
                $track['image'] = compact( 'src', 'width', 'height' );
                $track['thumb'] = compact( 'src', 'width', 'height' );
            }
'post_mime_type'    => $post['post_mime_type'],
            'link'              => get_permalink( $post['ID'] ),
            'guid'              => $post['guid'],
            'menu_order'        => (int) $post['menu_order'],
            'comment_status'    => $post['comment_status'],
            'ping_status'       => $post['ping_status'],
            'sticky'            => ( 'post' === $post['post_type'] && is_sticky( $post['ID'] ) ),
        );

        // Thumbnail.         $post_fields['post_thumbnail'] = array();
        $thumbnail_id                  = get_post_thumbnail_id( $post['ID'] );
        if ( $thumbnail_id ) {
            $thumbnail_size                = current_theme_supports( 'post-thumbnail' ) ? 'post-thumbnail' : 'thumbnail';
            $post_fields['post_thumbnail'] = $this->_prepare_media_item( get_post( $thumbnail_id )$thumbnail_size );
        }

        // Consider future posts as published.         if ( 'future' === $post_fields['post_status'] ) {
            $post_fields['post_status'] = 'publish';
        }

        // Fill in blank post format.

function has_post_thumbnail( $post = null ) {
    $thumbnail_id  = get_post_thumbnail_id( $post );
    $has_thumbnail = (bool) $thumbnail_id;

    /** * Filters whether a post has a post thumbnail. * * @since 5.1.0 * * @param bool $has_thumbnail true if the post has a post thumbnail, otherwise false. * @param int|WP_Post|null $post Post ID or WP_Post object. Default is global `$post`. * @param int|false $thumbnail_id Post thumbnail ID or false if the post does not exist. */
    

function get_oembed_response_data_rich( $data$post$width$height ) {
    $data['width']  = absint( $width );
    $data['height'] = absint( $height );
    $data['type']   = 'rich';
    $data['html']   = get_post_embed_html( $width$height$post );

    // Add post thumbnail to response if available.     $thumbnail_id = false;

    if ( has_post_thumbnail( $post->ID ) ) {
        $thumbnail_id = get_post_thumbnail_id( $post->ID );
    }

    if ( 'attachment' === get_post_type( $post ) ) {
        if ( wp_attachment_is_image( $post ) ) {
            $thumbnail_id = $post->ID;
        } elseif ( wp_attachment_is( 'video', $post ) ) {
            $thumbnail_id = get_post_thumbnail_id( $post );
            $data['type'] = 'video';
        }
    }

    

    public function column_title( $post ) {
        list( $mime ) = explode( '/', $post->post_mime_type );

        $attachment_id = $post->ID;

        if ( has_post_thumbnail( $post ) ) {
            $thumbnail_id = get_post_thumbnail_id( $post );

            if ( ! empty( $thumbnail_id ) ) {
                $attachment_id = $thumbnail_id;
            }
        }

        $title      = _draft_or_post_title();
        $thumb      = wp_get_attachment_image( $attachment_id, array( 60, 60 ), true, array( 'alt' => '' ) );
        $link_start = '';
        $link_end   = '';

        
if ( $has_password_filter ) {
            // Reset filter.             remove_filter( 'post_password_required', array( $this, 'check_password_required' ) );
        }

        if ( rest_is_field_included( 'author', $fields ) ) {
            $data['author'] = (int) $post->post_author;
        }

        if ( rest_is_field_included( 'featured_media', $fields ) ) {
            $data['featured_media'] = (int) get_post_thumbnail_id( $post->ID );
        }

        if ( rest_is_field_included( 'parent', $fields ) ) {
            $data['parent'] = (int) $post->post_parent;
        }

        if ( rest_is_field_included( 'menu_order', $fields ) ) {
            $data['menu_order'] = (int) $post->menu_order;
        }

        if ( rest_is_field_included( 'comment_status', $fields ) ) {
            
$calling_post_id = 0;

    if ( isset( $_GET['post_id'] ) ) {
        $calling_post_id = absint( $_GET['post_id'] );
    } elseif ( isset( $_POST ) && count( $_POST ) ) {// Like for async-upload where $_GET['post_id'] isn't set.         $calling_post_id = $post->post_parent;
    }

    if ( 'image' === $type && $calling_post_id
        && current_theme_supports( 'post-thumbnails', get_post_type( $calling_post_id ) )
        && post_type_supports( get_post_type( $calling_post_id ), 'thumbnail' )
        && get_post_thumbnail_id( $calling_post_id ) != $attachment_id
    ) {

        $calling_post             = get_post( $calling_post_id );
        $calling_post_type_object = get_post_type_object( $calling_post->post_type );

        $ajax_nonce = wp_create_nonce( "set_post_thumbnail-$calling_post_id);
        $thumbnail  = "<a class='wp-post-thumbnail' id='wp-post-thumbnail-" . $attachment_id . "' href='#' onclick='WPSetAsThumbnail(\"$attachment_id\", \"$ajax_nonce\");return false;'>" . esc_html( $calling_post_type_object->labels->use_featured_image ) . '</a>';
    }

    if ( ( $parsed_args['send'] || $thumbnail || $delete ) && ! isset( $form_fields['buttons'] ) ) {
        $form_fields['buttons'] = array( 'tr' => "\t\t<tr class='submit'><td></td><td class='savesend'>" . $parsed_args['send'] . " $thumbnail $delete</td></tr>\n" );
    }

?> <div <?php post_class( 'wp-embed' ); ?>> <?php         $thumbnail_id = 0;

        if ( has_post_thumbnail() ) {
            $thumbnail_id = get_post_thumbnail_id();
        }

        if ( 'attachment' === get_post_type() && wp_attachment_is_image() ) {
            $thumbnail_id = get_the_ID();
        }

        /** * Filters the thumbnail image ID for use in the embed template. * * @since 4.9.0 * * @param int|false $thumbnail_id Attachment ID, or false if there is none. */
return;
        }
        ?> <?php if ( is_singular() ) : ?> <figure class="post-thumbnail"> <?php                 // Lazy-loading attributes should be skipped for thumbnails since they are immediately in the viewport.                 the_post_thumbnail( 'post-thumbnail', array( 'loading' => false ) );
                ?> <?php if ( wp_get_attachment_caption( get_post_thumbnail_id() ) ) : ?> <figcaption class="wp-caption-text"><?php echo wp_kses_post( wp_get_attachment_caption( get_post_thumbnail_id() ) ); ?></figcaption> <?php endif; ?> </figure><!-- .post-thumbnail --> <?php else : ?> <figure class="post-thumbnail"> <a class="post-thumbnail-inner alignwide" href="<?php the_permalink(); ?>" aria-hidden="true" tabindex="-1"> <?php the_post_thumbnail( 'post-thumbnail' ); ?> </a> <?php if ( wp_get_attachment_caption( get_post_thumbnail_id() ) ) : ?>
return $content;
    }

    if ( wp_attachment_is( 'video', $post ) ) {
        $meta = wp_get_attachment_metadata( get_the_ID() );
        $atts = array( 'src' => wp_get_attachment_url() );
        if ( ! empty( $meta['width'] ) && ! empty( $meta['height'] ) ) {
            $atts['width']  = (int) $meta['width'];
            $atts['height'] = (int) $meta['height'];
        }
        if ( has_post_thumbnail() ) {
            $atts['poster'] = wp_get_attachment_url( get_post_thumbnail_id() );
        }
        $p = wp_video_shortcode( $atts );
    } elseif ( wp_attachment_is( 'audio', $post ) ) {
        $p = wp_audio_shortcode( array( 'src' => wp_get_attachment_url() ) );
    } else {
        $p = '<p class="attachment">';
        // Show the medium sized image representation of the attachment if available, and link to the raw file.         $p .= wp_get_attachment_link( 0, 'medium', false );
        $p .= '</p>';
    }

    
Home | Imprint | This part of the site doesn't use cookies.