如何在WordPress中通过POST_ID获取COMMENT_ID

时间:2014-05-22 作者:Jeevan

我用过get_comment() 但它的参数是$comment_ID 对于之前的评论,我必须手动输入wp_comments 取而代之的是,我需要根据post_ID. 然而wp_postswp_comments 与相关的post_IDcomment_post_ID, 所以我可以使用SQL查询来获取我尝试的comment\\u ID$wpdb->get_results(\'select comment_ID from wp_comments where comment_post_ID = 1\') 它甚至是手动过程,但至少我想通过从数据库中提取来传递comment\\u ID,但无法完成查询结果。因此,有没有任何方法可以为我可以获取post\\u ID的post\\u ID获取当前comment\\u ID$post->ID.

1 个回复
最合适的回答,由SO网友:ksr89 整理而成

使用get_comments( $args ) 获取帖子的所有评论。

$args= array(
    \'author_email\' => \'\',
    \'ID\' => \'\',
    \'karma\' => \'\',
    \'number\' => \'\',
    \'offset\' => \'\',
    \'orderby\' => \'\',
    \'order\' => \'DESC\',
    \'parent\' => \'\',
    \'post_id\' => 0,
    \'post_author\' => \'\',
    \'post_name\' => \'\',
    \'post_parent\' => \'\',
    \'post_status\' => \'\',
    \'post_type\' => \'\',
    \'status\' => \'\',
    \'type\' => \'\',
    \'user_id\' => \'\',
    \'search\' => \'\',
    \'count\' => false,
    \'meta_key\' => \'\',
    \'meta_value\' => \'\',
    \'meta_query\' => \'\');
您可以设置post_id 请点击此处获取与该帖子相关的所有评论。它与您的查询相同。

$comments = get_comments(array(\'post_id\'=> \'your post id\'));
$comment_ids = array();
foreach($comments as $comment):
    $comment_ids[] = $comment->comment_ID;
endforeach;
print_r(comment_ids);
供参考http://codex.wordpress.org/Function_Reference/get_comments

结束

相关推荐

PhpMyAdmin错误#1062-键“main”的条目“%1”重复

我是PHP新手!我正试图通过GoDaddy cPanel使用phpMyAdmin导入SQL文件(请不要取笑我)这是完整的读数-- -- Dumping data for table `wp_commentmeta` -- INSERT INTO `wp_commentmeta` (`meta_id`, `comment_id`, `meta_key`, `meta_value`) VALUES (1, 3, \'rating\', \'5\'), (37, 39, \'rating\', \'5\'),