acasmi
Forum Replies Created
Viewing 1 replies (of 1 total)
-
Forum: Hacks
In reply to: Get recent comments from a specific array of users?You have no idea how grateful I am for your help Pippin! Your tutorial was exactly what I needed. Thank you, thank you, thank you! ??
Here’s my working snippet (adjusted to only show 5 most recent) for anyone who needs it.
<?php //Many thanks to Pippin Williamson -https://pippinsplugins.com/get-comments-array-user-ids/ add_filter( 'comments_clauses', 'pw_comments_by_users', 10, 2 ); $comments = get_comments('number=5'); remove_filter( 'comments_clauses', 'pw_comments_by_users' ); function pw_comments_by_users( $clauses, $wp_comment_query ) { $clauses['where'] .= ' AND user_id IN (14,56,58,200)'; return $clauses; } if ( $comments ) { $output.= "<ul class=lastcomments>\n"; foreach ( $comments as $c ) { $output.= '<li>'; $output.= '<a href="'.get_comment_author( $c->comment_ID ).'">'; $output.= get_comment_author($c->comment_ID); $output.= '</a><p>'; $output.= get_comment_excerpt($c->comment_ID); $output.= '</br><span>Posted in: <a href="'.get_comment_link( $c->comment_ID ).'">'; $output.= get_the_title($c->comment_post_ID); $output.= '</a>'; $output.= ' on '. mysql2date('m/d/Y', $c->comment_date, $translate); $output.= "</span></p></li>\n"; } $output.= '</ul>'; echo $output; } else { echo "No comments made";}?>
Viewing 1 replies (of 1 total)