0

I am using wordpress3.5, I need to write post information to a file after I publish a post successfully.

What I am not know is

  1. When I click Publish button, what function wordpress invoke to save the post to mysql table wp_posts. I dive into wordpess's code ,found many many php file include.

  2. If I want to do more action, what should I do. For example, I want to write the post information to a file.

Thanks very much.

3

There are a number of hooks you can use, such as publish_post or save_post, e.g.:

// an example of a post save hook
add_action( 'save_post', 'diligents_post_save_hook' );
function diligents_post_save_hook( $post_id ) {
    //verify post is not a revision
    if ( !wp_is_post_revision( $post_id ) ) {
        // do things
    }

}

save_post will fire on publish and update, so be aware it will fire on saving of drafts etc. publish_post will run on publish, keep this in mind as it will not fire on update.

Saving data to a file is a step I cannot cover, as it is not a WordPress question, but a standard PHP question. For details on writing, reading, and saving to files, reference PHP.net

2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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