Support » Plugin: DCO Comment Attachment » How to get link image by get_comments

  • How can I get a link to an image that’s embedded in a comment by getting a list of comments?

    <?php $comments = get_comments($param) ?>
    <?php foreach($comments as $comment): ?>
       echo $comment->url_file ???
    <?php endforeach; ?>

    Thank everyone!

Viewing 1 replies (of 1 total)
  • After self-study, I know how to get the url image in the comment with the following code, this code put in the functions.php file.
    functions.php:

    function get_attachment_url_image_comment($comment_id) {
        $meta_key = 'attachment_id';
        $attachment_id = get_comment_meta( $comment_id, $meta_key, true );
        $full_img_url = wp_get_attachment_image_url( $attachment_id, 'full' );
        return $full_img_url;
    }

    view:

    <?php $comments = get_comments($param) ?>
    <?php foreach($comments as $comment): ?>
       echo get_attachment_url_image_comment($comment->comment_ID);
    <?php endforeach; ?>

    It works fine!

Viewing 1 replies (of 1 total)
  • You must be logged in to reply to this topic.