• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

I Like Kill Nerds

The blog of Australian Front End / Aurelia Javascript Developer & brewing aficionado Dwayne Charrington // Aurelia.io Core Team member.

  • Home
  • Aurelia 2
  • Aurelia 1
  • About
  • Aurelia 2 Consulting/Freelance Work

Speeding Up Slow WordPress CLI Commands

Wordpress · April 18, 2022

When performing intensive or long-running operations on a WordPress website, the admin panel is terrible. Have you tried to delete 100 posts from the posts screen? It’ll time out and delete maybe 10-20 if you’re lucky. This is one example of many.

Naturally, I opted for the WP CLI (WordPress CLI), which allows you to perform operations on your WordPress site from the terminal. I needed to delete custom post types from within a date range in my use case.

At first, I ran the command, which looked like this:

wp post delete $(wp post list --post_type='news' --posts_per_page=25000 --format=ids --meta_key="story_promoted_from_ingest" --meta_value="0" --start_date=2020-01-01 --end_date=2022-03-31) --force

This worked, but the performance was terrible. I was averaging maybe 20 posts per minute. It was taking forever to delete these. Not able to find a solution quickly, I deep-dived the WP CLI docs and found a heap of flags you can pass to it, most notably --skip-plugins and --skip-themes

What contributed to the slowness was some plugins triggering filters and actions as the posts were deleted.

wp post delete $(wp post list --post_type='news' --posts_per_page=65000 --format=ids --meta_key="story_promoted_from_ingest" --meta_value="0" --start_date=2020-01-01 --end_date=2022-03-31) --force --skip-plugins --skip-themes

By adding those two flags, it was a night and day difference. I was averaging close to 60 per minute (sometimes more). Skipping plugins and themes allows WP CLI to shed weight and run faster. Problem solved.

Dwayne

Leave a Reply Cancel reply

1 Comment
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Niccolò Zamborlini
Niccolò Zamborlini
5 months ago

Thanx!

0

Primary Sidebar

Popular

  • I Joined Truth Social Using a VPN and Editing Some HTML to Bypass the Phone Verification
  • Testing Event Listeners In Jest (Without Using A Library)
  • How To Get The Hash of A File In Node.js
  • Thoughts on the Flipper Zero
  • Waiting for an Element to Exist With JavaScript
  • How To Paginate An Array In Javascript
  • How To Mock uuid In Jest
  • How To Decompile And Compile Android APK's On A Mac Using Apktool
  • How To Get Last 4 Digits of A Credit Card Number in Javascript
  • Wild Natural Deodorant Review

Recent Comments

  • CJ on Microsoft Modern Wireless Headset Review
  • Dwayne on Microsoft Modern Wireless Headset Review
  • CJ on Microsoft Modern Wireless Headset Review
  • john on Microsoft Modern Wireless Headset Review
  • Dwayne on Why You Should Be Using globalThis Instead of Window In Your Javascript Code

Copyright © 2023 · Dwayne Charrington · Log in

wpDiscuz