• Resolved coyotecha

    (@coyotecha)


    I’m having problems finding the file wordpress uses to delete posts. I am trying to modify wordpress to update a different database when a posts is deleted by using the posts id when its deleted. I think its post.php but I’ve tried my code every which way there and tested it on other pages but it just won’t work on that page.

    Does anyone now another way I could do something like this.

Viewing 10 replies - 1 through 10 (of 10 total)
  • Michael Torbert

    (@hallsofmontezuma)

    WordPress Virtuoso

    Your post doesn’t make sense, or else you didn’t explain it very well. You want WordPress to delete a post from a second database instead of the one it normally uses?

    The action of deleting a post isn’t confined to one function in one file, so it really depends on what exactly you’re trying to do.

    Thread Starter coyotecha

    (@coyotecha)

    Let me try to explain it again. When a user deletes a post on edit.php I want to update a field in a different database. The other database has nothing to do with wordpress. The only thing i need to get is the post id of the posts and when the user presses delete update the other database.

    Hi,
    try to have a look at this hook :
    delete_post: Runs when a post or page is about to be deleted. Action function arguments: post or page ID.

    add_action(“delete_post”, “your_function”);

    Thread Starter coyotecha

    (@coyotecha)

    Should i add that hook as a plugin or in post.php

    It’ll be easier to add it as a plugin.
    And for update is still the best 😉

    Thread Starter coyotecha

    (@coyotecha)

    Tried something like this but it didn’t work :(. I’m guessing I am likely getting the id wrong.

    // Hook for deleting field
    add_action(“delete_post”, “delete_spec”);

    // function for above hook
    function delete_spec() {
    global $post;
    $thePostID = $post->ID;

    //blalla

    }

    Thread Starter coyotecha

    (@coyotecha)

    bump

    Michael Torbert

    (@hallsofmontezuma)

    WordPress Virtuoso

    delete_post already passes the post ID, so don’t call $post in your function (I don’t think you can outside the loop anyway). Looking up the delete_post action shows that it passes the post ID in an argument already, so having a parameter as such should do the trick.

    Thread Starter coyotecha

    (@coyotecha)

    Thanks

    so how does it pass the post id, how do I access the post id inside my function, I’ve looked everywhere and I can’t find this most basic bit of information explained, it’s just mentioned as if it’s so obvious

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Deleting posts and updating a database’ is closed to new replies.