Wordpress - 获取评论帖子的所有用户

时间:2016-01-30 08:25:30

标签: wordpress

我需要让所有对帖子发表评论的用户。并为每个用户提供评论。在线搜索但找不到任何解决方案。

4 个答案:

答案 0 :(得分:1)

如果post_id = 15那么

 <?php 
    $comments = get_comments('post_id=15');
    foreach($comments as $comment) :

        echo($comment->comment_author .'--coment--'.$comment->comment_content);
        echo '<br>';
    endforeach;
    ?>

有关详细信息https://codex.wordpress.org/Function_Reference/get_comments

,请参阅此处

答案 1 :(得分:0)

您可以从评论ID中获取评论编写者:

<?php $author = get_comment_author( $comment_ID ); ?>

你可以生成短代码使用它,这里会显示评论的所有信息。你需要提取哪一个是必需的。

 function input_func( $atts ) {
        global $post;
         $comments = get_comments( array( 'number' => 2, 'post_id' => get_the_ID() ) );
         print_r( $comments);
    }
    add_shortcode( 'input', 'input_func' );

答案 2 :(得分:0)

您需要get_comments()

以下是对特定帖子的评论:

<?php 
$args = array(
    'post_id' => 0, // Place post ID here.
    );
get_comments( $args ); 
?>

运行此代码后,您将获得一系列帖子和用户ID,您可以使用带有foreach的ID来获取每个用户的所有评论。像这样:

<?php 
$args = array(
'user_id' => 0, // Place user ID here.
);
get_comments( $args ); 
?>

答案 3 :(得分:-1)

<强>代码:

WP_Comment_Query

您可以在此处获取用户的电子邮件列表。

您也可以使用private String ns = ""; @Override public Object parse(InputStream in) throws XmlPullParserException, IOException { try { XmlPullParser parser = Xml.newPullParser(); parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, false); parser.setInput(in, null); parser.nextTag(); return readSkills(parser); } finally { in.close(); } } private Object readSkills(XmlPullParser parser) throws XmlPullParserException, IOException { parser.require(XmlPullParser.START_TAG, ns, "skills"); List<ESkill> skills = new ArrayList<ESkill>(); while (parser.next() != XmlPullParser.END_TAG) { if (parser.getEventType() != XmlPullParser.START_TAG) { continue; } String name = parser.getName(); // Starts by looking for the entry tag if (name.equals("skill")) { skills.add(readSkill(parser)); } else { skip(parser); } } return skills; } private ESkill readSkill(XmlPullParser parser) throws XmlPullParserException, IOException { /* <skill> <name>Software Engineering</name> </skill> */ String skill_name = ""; while (parser.next() != XmlPullParser.END_TAG) { if (parser.getEventType() != XmlPullParser.START_TAG) { continue; } String name = parser.getName(); if ("name".equals(name)) { skill_name = readName(parser); } else { skip(parser); } } return new ESkill().setSkill(skill_name); } // Processes title tags in the feed. private String readName(XmlPullParser parser) throws IOException, XmlPullParserException { parser.require(XmlPullParser.START_TAG, ns, "name"); String description = readText(parser); parser.require(XmlPullParser.END_TAG, ns, "name"); return description; } // For the tags title and summary, extracts their text values. private String readText(XmlPullParser parser) throws IOException, XmlPullParserException { String result = ""; if (parser.next() == XmlPullParser.TEXT) { result = parser.getText(); parser.nextTag(); } return result; } private void skip(XmlPullParser parser) throws XmlPullParserException, IOException { if (parser.getEventType() != XmlPullParser.START_TAG) { throw new IllegalStateException(); } int depth = 1; while (depth != 0) { switch (parser.next()) { case XmlPullParser.END_TAG: depth--; break; case XmlPullParser.START_TAG: depth++; break; } } }