I try to get all of the comments of the wordpress database related to a post, that I have decided that they have to be enabled and display them in the page, from the most recent to the oldest. These comments are a custom field with subfields. Is there a way to do this?
I've written the below code in the wordpress site up to now:
$texts = get_post_meta($post->ID, "texts", true);
if( $texts ) {
for( $i = 0; $i < $texts; $i++ ) {
$comment_text = get_post_meta( $post->ID, 'texts_' . $i . '_comment_text', true );
$comment_displayed = get_post_meta( $post->ID, 'texts_' . $i . '_comment_displayed', true);
if ($comment_text && $comment_displayed) {
$user = get_post_meta( $post->ID, 'texts_' . $i . '_user', true );
$user = getUserById($user);
$text_date = get_post_meta($post->ID, 'texts_' . $i . '_text_date', true );
echo $user->display_name;
echo html_entity_decode($comment_text);
echo $text_date;
}
}
}
Check if it works ?
function reverse_comments($comments,$id) {
$comments = array_reverse($comments);
return $comments;
}
add_filter('comments_array','reverse_comments',10,2);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.