繁体   English   中英

显示wordpress中从最新到最早的评论

[英]Display comments from the most recent to the oldest in wordpress

我试图获取与某个帖子相关的wordpress数据库的所有评论,我决定必须启用它们并将它们显示在页面中,从最新到最旧。 这些注释是带有子字段的自定义字段。 有没有办法做到这一点?

到目前为止,我已经在wordpress网站上编写了以下代码:

    $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;
                }
         }
         }

检查是否有效?

function reverse_comments($comments,$id) {
    $comments = array_reverse($comments);
    return $comments;
}
add_filter('comments_array','reverse_comments',10,2);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM