• Resolved Andrea

    (@licoreo)


    Good morning, If I delete a user from WordPress via code, WordPress automatically deletes all the posts created by that user (there are two types of posts saved in two different custom post types). However, they still remain on Algolia. How can I delete the posts created by that user? Reindexing the entire custom post type would also be acceptable. Thank you.

Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    I know we have re-index options via settings pages, and we have a WP-CLI command that can also be used for bulk re-indexing. Those are probably the best options at the moment.

    Otherwise, I think we’d need to look into triggering a bulk re-index on delete. That said, I wonder if all is well when re-assigning the user’s generated content to a different user.

    Thread Starter Andrea

    (@licoreo)

    i neri that is automate, esiste an action to trigger reindexing of single indice?

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    With the WP-CLI, you can specify which index to re-index.

    Example:

    wp algolia reindex posts_post

    https://github.com/WebDevStudios/wp-search-with-algolia/wiki/WP-CLI

    With the UI in browser and WP admin, each has their own.

    Thread Starter Andrea

    (@licoreo)

    exists a way to do with php?

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Let me have a chance to dig in to some things and I’ll get back to you asap.

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    I remembered a case where I set up re-indexing specific posts, in this case WooCommerce products, upon completed purchases, so this is adapted from that.

    https://gist.github.com/tw2113/3f8729526bc25c3778a41e42f9173601

    Out of box for this, it’ll just do the searchable_posts index, and any index for autocomplete will need to be added. There’s commented out code for that and notes on how to handle that. Hopefully that section makes sense, but feel free to ask questions.

    That said, this code was originally meant to handle only 1 post/object at a time, and in your situation, it’s a complete reindex of everything in the index. I can’t promise anything around timeouts for the request and whatnot, so performance may be degraded, especially for big indexes.

    Because of that as well, I don’t think we’d consider adding this to the core plugin. It’d be better adapting this to some sort of background action scheduler with a queue. However, at minimum, this snippet shows how to potentially set things up and run things on a specific action.

    Thread Starter Andrea

    (@licoreo)

    Hello,

    looks a great solution, thank you!

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Hopefully not a huge amount of performance is lost because of the volume of re-indexing.

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘delete user’ is closed to new replies.