Skip to content

Add example of how to search and delete results #51

Closed

Description

@danielbachhuber

For those wanting to clean up parts of their database, it'd be neat to have a wp db search example indicating how to search for a string and delete the resulting database entry.

danhgilmore [7:14 AM] I think I've asked this in the past, but I'm just now getting back to working with wp-cli....is there a way to search/delete instead of search/replace?
[7:15] I am cleaning up our DB, and there's a lot of things orphaned in the wp_X_options tables that I'd like to search for and then remove.
janw.oostendorp [7:37 AM] pass an empty string within quotes? Won't delete empty meta/options
danhgilmore [7:38 AM] Yeah, I'm trying to remove the records from the database 😕

From https://wordpress.slack.com/archives/C02RP4T41/p1506435293000491

Activity

  1. marksabbath commented on Dec 2, 2017

    @marksabbath
    Collaborator

    Hey @danielbachhuber I couldn't find a properly command/method to perform this kind of action, however, while reading the code of wp db seach, I figured that we could add a new arg to wp db search, something like --delete-records, which would properly fit in these cases.

    What are your thoughts about this idea? If you do think that this would be a good idea, I could volunteer to implement that.

  2. schlessera commented on Jan 8, 2018

    @schlessera
    Member

    @marksabbath I think that would make more sense as a separate command, as deleting rows is not a variation of "searching", but rather a completely different operation.

    Also, it would need safety features like --dry-run or --interactive.

    Do you care to add this as a new issue to wp-cli/ideas to discuss in more detail?

  3. marksabbath commented on Jan 10, 2018

    @marksabbath
    Collaborator

    You bet @schlessera gonna add that there right away.

  4. missjwo commented on May 19, 2018

    @missjwo

    Not sure if this is helpful, but I recently just had to do

    wp user delete $(wp db query 'SELECT ID FROM wp_users WHERE user_email NOT LIKE \"%@domain.example\"' --skip-column-names) --network --yes'
    

    for a project

  5. danielbachhuber commented on Jan 24, 2019

    @danielbachhuber
    MemberAuthor

    Addressed in #122

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions