Php 使用wp_list_comments()在wordpress中使用meta键过滤评论
基本上,我试图用“meta_key”和value来过滤评论。我已经得到评论元数据,但回复链接没有出现。谁能帮我摆脱这一切。我尝试使用wp_list_comments(),但我不知道如何使用meta_键值 以下是代码:Php 使用wp_list_comments()在wordpress中使用meta键过滤评论,php,wordpress,Php,Wordpress,基本上,我试图用“meta_key”和value来过滤评论。我已经得到评论元数据,但回复链接没有出现。谁能帮我摆脱这一切。我尝试使用wp_list_comments(),但我不知道如何使用meta_键值 以下是代码: <div class="comment-section"> <?php $issue = array( 'meta_query' => array( array( '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 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();
}
基本上,我需要在自定义类型中使用meta_键过滤注释