Your approach will be very slow if there are N no of comments. Use following approach for much faster execution.
global $wpdb;
$sql="
SELECT GROUP_CONCAT( comment_ID ) AS ids
FROM `wp_comments`
WHERE comment_post_ID = ".$POST_ID;
$ids = $wpdb->get_results($sql, ARRAY_A);
if(isset($ids[0]['ids']) && $ids[0]['ids'] != ''){
$wpdb->query('
UPDATE wp_commentmeta
SET meta_value = 0
WHERE comment_id IN ('.$ids[0]['ids'].')
AND meta_key = "accepted"
');
}
P.S : Haven’t tested the code.
Related Posts:
- What for is the table “wp_commentmeta” exactly?
- Running a function on comment status change
- Is it possible to show custom comment metadata in the admin panel?
- Add Comment Custom Field
- Upload images with comment
- Add a drop down list to comment form?
- An action hook where a comment meta is updated
- What are the additional fields in wp_comments used for?
- Display comment meta data after quick update
- WordPress Comment. Need some details of wp_comments DB table
- How would I count the number of times a comment meta field’s value is in a post’s entire comments?
- Get comments from post and sort by commentmeta value
- How to sort posts by the average of comment meta values
- How to get a value from comment meta
- Name of comment field differs on different sites
- Make every comment go to the spam folder
- How to display comment meta under each comment content
- How to get Post title by locale with Qtranslate-X
- get_comment_meta not behaving as expected
- How to filter comments by comment_meta
- Top rated posts Average rating issue
- WordPress Commenting System User access and Security
- Add comment meta
- Comment-Meta doesn’t work with latest wordpress update
- add field comment [duplicate]
- Use country flag as user avatar based on comments IP address?
- How to rearrange fields in comment_form()
- Commenting in user profile page?
- How do I delete all comments from a specific old blog post?
- Removing the “Website” Field from Comments and Replies?
- How to load and show comments with AJAX instead of pagination?
- Comments not appearing at all
- Hook/Filter before and after comments
- Comment form validation
- I have tried using Plugins to remove 72K comments with no success
- Display commenter’s registration date on comments?
- show un-approved comments at wordpress front end
- How to add consent checkbox in comment section
- How to add pagination to comments?
- WP 4.4.1 allow empty comments via add_action ‘pre_comment_on_post’
- How to get replies of a comment?
- Share comment to twitter after publishing [closed]
- changing comment-page-# to something like review-page-#
- show if comment is in moderation
- Deleting the attached “comment replies” when trashing a comment
- How can I get a list of comments by target
- Load comments.php template outside the post loop
- Auto-fill Custom comment fields
- Highlighting the current users comment
- How to auto empty comment trash after X days
- comments.php keep comment date/time but remove date/time’s #hyperlink
- Control panel loads slowly due to 2 slow queries on comment table
- Display complete comment section via post ID
- Comment Pagination Behavior wp_list_comments() – comment ordering and pagination
- Check if comment was successfully submited
- After Submitting Comment Form Shows an Empy Page in WordPress
- Unique User for all visitor, but possibility to comment with unique name
- comments_array filter doesn’t work in some themes
- Redirect when click on “response” in comment section
- Link to a User’s Forum Profile From Their Comment
- if user role is then echo text
- strange behavior with comment position
- Safely editing core files
- Way to count the number of people who have commented on a post?
- Batch approve comments
- Disable comments and pingbacks on old custom post types
- Add paragraph tags to comments
- How to tweak comment fields properly from functions.php
- How to allow duplicate comments?
- How to permanently delete pages I have already trashed?
- How to change comment texts that has a specific comment_ID – Hook into comment
- How does WP decide how to display a page
- counting trackbacks, pingbacks and comments of a post
- Adding comments section to website integrated WordPress instance
- How to Define Custom Number of Items in Comment Feed
- How indicate when a functions was upgraded in relationship to the entire program [closed]
- Empty comments field or
- infinite loop on page with comments after changing comments.php and header.php
- What templates/funtions needed in custom theme to allow comments the new 3.0 way
- Default Gravatar not showing for pings
- How include comment and post count of user in this custom query
- How can I hide comment of the authors from their published posts?
- How to customize ‘children comments’ in WordPress?
- Disallow Comments
- Keep comment author’s name on their comment even when their account is deleted
-   not working in comments
- Comments.php is not getting called on main blog page
- Allowing comments on author pages
- Comment section not appearing on posts
- How can I see whether a commenter has subscribed to be notified of replies / other comments to a post
- Where is the Leave a Comment link set
- Disable comment moderation in multisite
- URLs to user page is broken
- Auto disable comments with custom field
- I want to fill the comment with the comment count?
- delete user not working
- How to remove or customize “Comment” in comments form?
- Getting thousands of spam comments
- check if a comment was made by a registered user
- comment_approved custom value