• Resolved stuureenswatnaarhugo

    (@stuureenswatnaarhugo)


    Hello,

    I want to show the user/author’s comments on his/her author page. I would like to show the attachments added by ‘comment attachments’.

    Doe anybody know how to get the attachments on a non-comments page (like in the WP Admin comments section?)

    This is the function I use for showing comments on the author page (author.php)

    <?php
    $author_id = get_the_author_meta( 'user_id' );
    $args = array(
        'author_id' => $author_id,
        'number' => '10'
    );
    $comments = get_comments($args);
    foreach($comments as $comment) :
        echo('<li class="comment">' . $comment->comment_content),'<h5><a href='.get_permalink($comment->comment_post_ID).'>', get_the_title($comment->comment_post_ID), '</a></h5>', '<time><em>' . $comment->get_comment_date . '</em></time>', '</li>';
    endforeach;?>

    https://wordpress.org/plugins/comment-attachment/

Viewing 3 replies - 1 through 3 (of 3 total)
  • I needed something like that and built this snippet. I believe you can adapt to get the comments from an specific user using the information here: http://codex.wordpress.org/Class_Reference/WP_Comment_Query

    function get_comments_images($post_id){
    
    	$comments_query = new WP_Comment_Query;
    	$comments = $comments_query->query( array(
    		'post_id' => $post_id,
    		'status' => 'approve',
    		'meta_query' => array(array(
    			'key' => 'attachmentId'
    			)),
    		'fields' => 'ids'
    		) );
    
    	$images_url = array();
    
    	foreach ($comments as $key => $comment_id) {
    
    		$attachmentId = get_comment_meta( $comment_id, 'attachmentId', true );
    		$attachmentUrl = wp_get_attachment_url( $attachmentId );
    		$images_url[] = $attachmentUrl;
    
    	}
    
    	return $images_url;
    
    }

    😉

    Plugin Author latorante

    (@latorante)

    Just came back after a while to my plugins,

    will create a wishlist in my notebook of all suggestions people write in forums, and put them in slowly. 🙂

    Mart

    Saw this post, this is exactly what I was looking for!

    I’ve installed the Comment Attachment plugin and it’s all working fine, on the comment page.. What i actually want is to show the latest comments WITH the attachment on my homepage. For now I’m only getting the comment on my homepage, but it seems he can’t find the attachment.

    I’ve tried to implement the code from IrisRosa but it’s not working for me.
    As I am a noob with PHP so I think I’m missing some bits of code 🙂
    All I want is a simple for loop with the output of the latest comments including the attachments

    Can someone help me fix this?
    Thanks!!

    [ No bumping please. ]

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Show Attachments on Author Page’ is closed to new replies.