【问题标题】:WP - How to get all the comment_post_ID in bulk comment approvalWP - 如何在批量评论批准中获得所有的comment_post_ID
【发布时间】:2017-03-18 02:10:06
【问题描述】:

当我批量批准 cmets 时,它只会得到一个 comment_post_ID
我需要得到所有的comment_post_ID

这段代码:

add_action('transition_comment_status', 'my_approve_comment_callback', 10, 3);

function my_approve_comment_callback($new_status, $old_status, $comment) {

    if ($old_status != $new_status && $new_status == 'approved') {
        $my_file = fopen("/tmp/postidlist.txt", "w");

        $comment_id_2 = get_comment($comment->comment_ID);
        $comment_post_id = $comment_id_2->comment_post_ID;

        fwrite($my_file, $comment_post_id);
        fclose($my_file);
    }
}

【问题讨论】:

    标签: php wordpress file comments fopen


    【解决方案1】:

    其实问题出在fopen()模式;你正在使用w 哪个代表覆盖现有内容的写入模式,您 必须使用a 模式,该模式用于将内容附加到现有 文件。

    替换此行

    $my_file = fopen("/tmp/postidlist.txt", "w"); 
    

    有了这个

    $my_file = fopen("/tmp/postidlist.txt", "a"); 
    

    希望这会有所帮助!

    【讨论】:

      猜你喜欢
      • 2011-11-19
      • 1970-01-01
      • 1970-01-01
      • 2020-10-24
      • 2019-02-16
      • 2012-02-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多