- To get the comments use
get_comments()
and the current post’s ID. - To get the URL fields only use
wp_list_pluck()
. - To remove the empty fields use
array_filter()
without a callback.
.
$comment_urls = array ();
$all_comments = get_comments( array ( 'post_id' => get_the_ID() ) );
if ( $all_comments )
{
$comment_urls = array_filter(
wp_list_pluck( $all_comments, 'comment_author_url' )
);
}
$comment_urls
is now an array of URLS. Don’t forget to use esc_url()
when you print those into your page.
You could also filter 'comments_clauses'
to query for comments with a non-empty URL field only. That might be faster.
add_filter( 'comments_clauses', 'wpse_66056_get_urls_only' );
function wpse_66056_get_urls_only( $sql )
{
remove_filter( current_filter(), __FUNCTION__ );
$sql['where'] = $sql['where'] . " AND comment_author_url != ''";
return $sql;
}
$all_comments = get_comments(
array (
'post_id' => get_the_ID(),
)
);
$comment_urls = wp_list_pluck( $all_comments, 'comment_author_url' );