WP - 如何在批量评论批准中获得所有 comment_post_ID
WP - How to get all the comment_post_ID in bulk comment approval
当我批量批准评论时,它只得到一个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);
}
}
Actually the problem lies in the fopen()
mode; you are using w
which stantds for write mode which overwrite the existing content, you
have to use a
mode which is used for append content to the existing
file.
替换此行
$my_file = fopen("/tmp/postidlist.txt", "w");
有了这个
$my_file = fopen("/tmp/postidlist.txt", "a");
希望对您有所帮助!
当我批量批准评论时,它只得到一个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);
}
}
Actually the problem lies in the
fopen()
mode; you are usingw
which stantds for write mode which overwrite the existing content, you have to usea
mode which is used for append content to the existing file.
替换此行
$my_file = fopen("/tmp/postidlist.txt", "w");
有了这个
$my_file = fopen("/tmp/postidlist.txt", "a");
希望对您有所帮助!