最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

functions - Display images that are not in the content

programmeradmin0浏览0评论

The function below returns all the images attached to the post, however, if I delete the image inserted into the content, it still returns in the function, because the media is still as attached to the post.

So, how do I really bring only the images inserted in the content of the post?

<?php 
$args = array(
        'post_type'   => 'attachment',
        'posts_per_page' => -1,
        'post_mime_type' => 'image',
        'post_parent' => $post->ID,
    );

    $attachments = get_posts( $args );

    if ( $attachments ) {

        foreach ( $attachments as $attachment ) {

            echo wp_get_attachment_image( $attachment->ID, false );
            echo '<hr>';
            echo '<br>';

        }
    }
?>
发布评论

评论列表(0)

  1. 暂无评论