admin管理员组文章数量:1414908
I need to get comments and their replies from database to show them as json for an android app, so how can i tell if a comment has replies (get their number ) , and how can i list replies nested with their parent comments to show
This is my code if functions.php
// Comments
add_action('rest_api_init', function () {
register_rest_route( 'wp/v2', 'comments/(?P<category_id>\d+)',array(
'methods' => 'GET',
'callback' => 'get_latest_comments'
));
});
function get_latest_comments($request) {
global $wpdb;
$postID = $request['post_id'];
$args = array(
'comment' => $request['post_id']
);
$request = "SELECT * FROM $wpdb->comments";
$request .= " JOIN $wpdb->posts ON ID = comment_post_ID";
$request .= " WHERE comment_approved = '1' AND post_status = 'publish' AND post_password =''";
$request .= " AND ID='{$postID}' and comment_parent=0";
$list = $wpdb->get_results($request);
return $list;
This is the output now
comment_ID "21"
comment_post_ID "172"
comment_author "user"
comment_author_email "[email protected]"
comment_author_url ""
comment_author_IP "***.65.78.45"
comment_date "2019-09-06 13:46:50"
comment_date_gmt "2019-09-06 13:46:50"
comment_content "Test Comment"
comment_karma "0"
comment_approved "1"
...
but i would like to get a nested list with comments and replies , or at least comments and number of replies of each comment
本文标签: databaseHow to rerieve comments and their replies from DB
版权声明:本文标题:database - How to rerieve comments and their replies from DB 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745173367a2646109.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论