Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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.

share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

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

share|improve this answer
    
thanks Tom , I know what should I to do next.... –  diligent Jul 3 '13 at 9:17
    
Well you will want to use the $post_id to grab data about the post, and then write it out in a file in the desired format. $post = get_post( $post_id ); is your friend here –  Tom J Nowell Jul 3 '13 at 10:22
    
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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