WP-CLI is a powerful tool, but when you’re dealing with a huge volume of comments, it might not always behave as expected.
Recently, I tried to use WP-CLI to move all pending comments to spam. The list includes over 67,000 unapproved comments. When I tried to list all the comments, WP-CLI returned odd outputs like 67844%. Here’s how I solved it using direct SQL commands.
The Problem
Running the following command returned a strange output 67844%
wp comment list --status=hold --format=count
When I debugged with the help of ChatGPT, I realized that WP CLI may not behave as expected when working with large number of results.
So I chose to get the job done using SQL query. All I had to do was to run the following query.
UPDATE wp_comments SET comment_approved = 'spam' WHERE comment_approved = '0';
// To verify the result, run
SELECT COUNT(*) FROM wp_comments WHERE comment_approved = '0';
Next time, when WP CLI lets you down, don’t hesitate to hit the SQL query.
Today, I’m grateful for my consulting gig, which allows me to work from my home office and spend quality time with my family.
Leave a Reply