好吧,注释(如果我记得正确,并且v4中没有任何更改)是自定义的帖子类型,因此您可以向其中添加post\\u meta,如response => true (阳性)或false (否定)。
然后你可以进行自定义查询(WP_Comment_Query ) 使用元参数(ak。Custom Field Parameters )
你需要2个查询,1个返回正面评论,2个返回负面评论。。
其他一切取决于您的设计。。
啊,是的。当发布评论时,你需要创建一些字段来保存帖子,无论是正面的还是负面的。。。
Elaborating my answer:
好的,例如,在前端(FE)u have表单上,witch向某个帖子提交评论。你需要(如果你还没有)一些字段来确定什么是“好”或“坏”的评论。让我们调用这些字段
response (让我们想象一下,这是一个单选按钮,有两个选择:
good 和
bad 作为值)。
然后,当用户提交表单时,他必须选择一个单选按钮,在php端(后端),您将得到他的答案(string) $_POST[\'response\'].现在你有了一个变量$response 其中包含1个单选按钮值。
接下来,u需要在数据库中插入新注释(例如使用wp_insert_comment 函数)它将返回新的注释ID。
接下来,你需要存储你的response 对这些注释使用add_comment_meta 传递新注释ID的函数,UNIQUE名称表示response 输入数据库(例如:_response ) 和一个值($响应)(最后一个参数-唯一,最好是真实的)。。。
所以,现在数据库中有了注释,数据库中有了注释元。
现在,您可以查询数据库以获取某些帖子/页面的所有评论,如下所示:
<?php
$args = array(
\'post_id\' => get_the_id(), // or if u have some variable u could use it to get all comments from post/page
\'meta_key\' => \'_response\', // from add_comment_meta - unique name representing key in database
\'meta_value\' => \'good\' // "good" or "bad" or whatever u desire to be
);
// The Query
$comments_query = new WP_Comment_Query;
$comments = $comments_query->query( $args );
// Comment Loop
if ( $comments ) {
foreach ( $comments as $comment ) {
$response = get_comment_meta( $comment->comment_ID, \'_response\', true ); // store response to $response variable for later use
echo \'<p>\' . $comment->comment_content . \'. <span>These comment is:\' . $response . \'</span></p>\'; // the output of a comment
}
} else {
echo \'No comments found.\';
}
?>
这样,你可以得到两个不同的查询,一个是好的评论,另一个是坏的评论,并在页面的不同位置(左侧、右侧)进行回应。
基本上,它与CPT和get\\u post\\u meta-only评论相同。。。如果你能思考如何用特定的元值查询CPT,那么你可以通过注释来完成。。
相关链接:https://codex.wordpress.org/Class_Reference/WP_Comment_Queryhttps://codex.wordpress.org/Function_Reference/add_comment_meta
如果您有什么问题,请随时提问。。