繁体   English   中英

使用 wp_list_comments() 在 wordpress 中使用元键过滤评论

[英]Filter comments with meta key in wordpress using wp_list_comments()

基本上我试图用'meta_key'和值过滤评论。 我得到了评论元数据,但没有出现回复链接。 任何人都可以帮助我解决这个问题。 我尝试使用 wp_list_comments() 但我不知道如何使用 meta_key 值。

这是代码:

   <div class="comment-section">
<?php
$issue = array(
'meta_query' => array(
        array(
            'key'   => 'comment-type',
            'value' => 'Idea'
        )
    )
);

$comments_query = new WP_Comment_Query;
$comments       = $comments_query->query( $issue );

if( $comments ) :
    foreach( $comments as $comment ) :
        ?>
            <div class="comment-author vcard">
    <?php echo($comment->comment_content);?>
                <div class="reply"><?php
                // Display comment reply link
                comment_reply_link( array_merge( $args, array(
                    'add_below' => $add_below,
                    'depth'     => $depth,
                    'max_depth' => $args['max_depth']
                ) ) ); ?>
                </div>
            </div><!-- .comment-details -->
    <?php
    endforeach;
endif;
?>
</div>

请让我知道如何显示回复链接。

你可以试试这个 function 我猜


function wp_filter_comment( $commentdata ) {
    if ( isset( $commentdata['user_ID'] ) ) {
        /**
         * Filters the comment author's user ID before it is set.
         *
         * The first time this filter is evaluated, 'user_ID' is checked
         * (for back-compat), followed by the standard 'user_id' value.
         *
         * @since 1.5.0
         *
         * @param int $user_ID The comment author's user ID.
         */
        $commentdata['user_id'] = apply_filters( 'pre_user_id', $commentdata['user_ID'] );
    } elseif ( isset( $commentdata['user_id'] ) ) {
        /** This filter is documented in wp-includes/comment.php */
        $commentdata['user_id'] = apply_filters( 'pre_user_id', $commentdata['user_id'] );
    }
 return $commentdata;
}

我已经解决了

 $comments = get_comments(array(
    'post_id' => $post->ID,
     'status' => 'approve',
       'type' => 'comment',
    'meta_key' => 'comment-type',
    'meta_value' => 'Issue',
  ));
        if($comments)
        {
  wp_list_comments(array(
    'per_page' => 10, // Allow comment pagination
   ), $comments);
        }
        else 
        {
            
            comment_form();
        }

暂无
暂无

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

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