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
Related Posts:
- How to get posts published between a date and today?
- Is it possible to Schedule Attachments in WordPress?
- Publish pending article from front end with a button?
- How to limit user to publish post per day and per role?
- Query posts distinct authors
- How to get previous 10 days post from a specific date – WP Query
- Restrict the Number of Posts an Author can Publish (over time)?
- Can’t show comments count per post outside loop
- Only display posts with comments
- Hiding by default specific post status on backend list?
- Detect Post Type when publish_post is ran
- What Can I Use To Add A Custom Button Between Publish button and Move To Trash?
- publish_post conflicts with save_post
- Filter Posts By Tag
- Can I set and show “important” post in my blog?
- Notification to Admin or Author upon new post [duplicate]
- What differences are there between a Privately Published post and a Draft post?
- previewing my posts on static page?
- Exclude newest post from category X but show rest
- Reset Popular post query?
- How to give capability (publish contributors posts) to author role?
- Display posts with tag that matches current post title
- Why is querying posts messing up my pages?
- Print a message if excerpt is empty after posts have been publish/update!
- Category Foreach keeps looping?
- Check if checkbox is marked on publish/update post
- Prevent scheduled post being published if date/time is past current date/time
- Calling Different Custom Post Timestamps in a table
- Multi row post list
- Copy post to separate database with “add_action(….)”
- How to make multiple sections in home pulling posts category wise?
- Query Posts by Custom Field
- Order posts alphabetically: how to set order=asc in mysql query?
- How to order posts in an arbitrary order?
- How do I manage my users post before publish?
- How to get posts from a current post’s month?
- Wrong post title displayed from loop
- WordPress query_posts by tag doesn’t work anymore(?)
- While loop articles – if statement order
- Conditionals if tags exist?
- WordPress website loads more posts than expected
- Get the amount of posts on a current page
- Posts – display all posts except a post by an ID
- query post limits
- why the same code got different results when using query_posts in functions.php and index.php
- Archive template combined with post slider and regular posts
- How to get posts published on the latest date?
- How to only publish posts with image in it
- Display password protected posts to logged in users
- WordPress bulk category select when publishing post
- How to check in functions.php if there is data in a WP_Query?
- Post Filtering by GET URL parameters
- WP_Query: Show 10 posts in date order, first three random
- Get post by tag
- Random posts that always include a particular post?
- Post: how to set created date after post has been published [closed]
- Bootsrap carousel for post
- All categories displays the same posts
- Query function not executed between element [closed]
- Echo the number of posts being displayed
- Exclude a category of posts in author template
- Display specific posts on home page
- Publish a Silent Post without updating Feed
- WordPress displays post on subcategory only
- Get posts from current category?
- Change content off every sixth element
- Move position in post list for a custom checkbox column
- Show posts from two specific category in WP_Query
- How to set a Post’s default visibility to ‘Private’ in Gutenberg?
- How to create loop of posts except post ID defined via ACF field
- Send email to user when I publish a new post
- My posts are getting to Auto draft when I try to Publish
- WordPress get tags in “publish_post” hook
- How to display particular categorie’s post which associated to specific user?
- post is not showing more than 3949 words
- wp_query args with relation
- Create blog post from external source and set publication date
- How to correctly escape data
- Use special template for the first post in the loop
- Blog posts not displaying on blog posts page
- Repeating post how to solve this
- Sort Events by Venue Title – Sort Post set by related post ids
- Get posts by category or author
- show latest authors blog post
- How to get only current images of a post
- Why I obtain this WP_Query strange behavior trying to select posts having a specific tag?
- How to Test a Blog Post for Update vs. Publish Status — Unique
- How to pass multiple checkbox values to wordpress query?
- How to handle a post before publishing?
- How to get all post titles starting with numbers and symbols?
- How to inject a post within a loop
- wp_query select if have comments
- Creating pages and getting their values from the database table
- Return All Post from publish to draft [duplicate]
- I am creating a front end dashboard where I need to show all the posts by the current user. So, I need to show posts in publish
- query_posts different amount of posts per page [duplicate]
- Sort Posts Alphabetically Based on Specific Category (Divi)
- How to change url of posts?
- How to show related posts by detecting the current category?
- Display posts on a custom page from only a specific category?