-1

I have a few sites that I wish to slim down. The sites have been active for a long time and there is really old post data that is no longer relevant. I wish to delete those (older then 3 years) and there meta data, their attached media, revisions and including W3 cache files. Also a database cleanup can help a bit.

Which method is best?
1. Plugin 'Bulk delete' with pro addon delete 'delete attachment'
2. wp-cli post delete
3. WP api function

  • Many good questions generate some degree of opinion based on expert experience, but answers to this question will tend to be almost entirely based on opinions, rather than facts, references, or specific expertise. Choose what fits YOU best. – leymannx Jun 20 at 8:29
  • 1. Costly addon with yearly billing seems a bit much 2. Seems like a good solution with a bit of a leaning curve. Could a solution be like: wp post delete $(wp post list) ref: developer.wordpress.org/cli/commands/post/delete is data_query before parameter support as for wp_query? developer.wordpress.org/reference/classes/wp_query/… or just the 'AVAILABLE FIELDS' in developer.wordpress.org/cli/commands/post/list 3. Need a bit of extra work – zebrastribe Jun 20 at 8:52
  • 1
    Working on the wp-cli solution, thanks Leymanx :-) There seems to be a limit of a 1000 posts when using the 'before' and 'after' github.com/wp-cli/wp-cli/issues/3039 So the command would be only work for one year at the time but look like this: wp post delete $(wp post list --post_type=post --format=ids --year=2008) @leymannx, is this correct? – zebrastribe Jun 20 at 9:32
  • This looks good. I'd always prefer wp-cli as well for stuff like this. Better test it on a local copy of your site first. – leymannx Jun 20 at 10:33
  • Great, also if the argument gets to long I will use '--posts_per_page=10000': ericbusch.net/… wp post delete $(wp post list --post_type=post --format=ids --year=2008 --posts_per_page=10000) Do you know if the media, comments and meta data associated with the deleted posts also gets deleted? – zebrastribe Jun 20 at 10:54
0

I will use the wp-cli version:
wp post delete --force $(wp post list --post_type=post --format=ids --year=2008 --posts_per_page=10000)

I added the --force so that it will delete the post and not just put them in the trash.

Not the answer you're looking for? Browse other questions tagged or ask your own question.