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
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745173368a4615062.html
评论列表(0条)