我会使用WP_Comment_Query
.
function comment_where_wpse_108654($clauses) {
$clauses[\'where\'] .= \' AND DATE(comment_date) = "\'.date(\'Y-m-d\').\'"\';
remove_filter(\'comments_clauses\',\'comment_where_wpse_108654\');
return $clauses;
}
add_filter(\'comments_clauses\',\'comment_where_wpse_108654\');
$args = array(
\'post_id\' => $post->ID,
\'number\' => 1,
\'orderby\' => \'comment_date\',
\'order\' => \'desc\'
);
$comment_qry = new WP_Comment_Query;
$comment = $comment_qry->query( $args );
假设
$post->ID
是正确的。
现在,如果主题正在构建注释ID,那么echo get_permalink().\'/#comment-\'.$comment[0]->comment_ID;
应该是您评论的链接。
编辑:您似乎对如何使用多个帖子/评论进行编辑感到困惑。
function comment_where_wpse_108654($clauses) {
$clauses[\'where\'] .= \' AND DATE(comment_date) = "\'.date(\'Y-m-d\').\'"\';
return $clauses;
}
add_filter(\'comments_clauses\',\'comment_where_wpse_108654\');
foreach ($results as $id) {
$args = array(
\'post_id\' => $id->ID, // your $id->ID should work just as well
\'number\' => 1,
\'orderby\' => \'comment_date\',
\'order\' => \'desc\'
);
$comment_qry = new WP_Comment_Query;
$comment = $comment_qry->query( $args );
if (!empty($comment[0])) { ?>
<li><a href="<?php echo get_permalink().\'/#comment-\'.$comment[0]->comment_ID; ?>" rel="bookmark"><?php the_title(); ?></a></li><?php
}
}
remove_filter(\'comments_clauses\',\'comment_where_wpse_108654\');