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:
- Keep featured content post in homepage with original order
- How to get posts published between a date and today?
- add action only on post publish – not update
- How to show related posts by category
- How to prevent posts from being published too close to each other?
- the_author() returns empty string
- Is it possible to Schedule Attachments in WordPress?
- Elegant way to include only published posts with get_objects_in_term()?
- Display all posts from specific categories on a page
- WordPress plugin to publish to multiple remote WordPress blogs
- Post publish only hook?
- Publish pending article from front end with a button?
- How to exclude latest x posts from a paginated query?
- How to add a “publish” link to the quick actions
- How to limit user to publish post per day and per role?
- Display content from a specific category
- How to display posts by current user/author in a custom page template?
- post_name empty after wp_insert_post
- Query posts distinct authors
- When a user creates a post (pending), send a confirmation link that allows them to publish
- How to get previous 10 days post from a specific date – WP Query
- In what sequence are the hooks fired when a post is “published”?
- Number of posts per page setting is not working?
- Restrict the Number of Posts an Author can Publish (over time)?
- Add javascript when post is published
- WordPress Posts Out Of Order after 3.1 Update
- featuring old articles without messing up with the archive
- Query only Posts from Both of Two Category?
- Insert custom div between posts
- Can’t show comments count per post outside loop
- Publish posts only after the condition is met
- Only display posts with comments
- Hiding by default specific post status on backend list?
- Order post by year DESC and month ASC
- WordPress get posts by date without query_posts
- Detect Post Type when publish_post is ran
- How to Display Post View Count
- How can I display a specific user’s first published post?
- Different amount of posts on homepage than paged pages
- Does WordPress remove draft status automatically?
- Assign a day of the week to post, e.g: Assign Monday to post and have it only appear when the day is Monday
- Bulk Post update_post_meta
- Show 5 posts and than 3 posts offset with pagination
- wp_query args with relation
- WP_Query to get posts in a specific tag or has post_format
- Make recent post display recent updated, instead of recent published
- Create blog post from external source and set publication date
- Manipulate query to show specific post
- Querying posts from current category, using a variable as array argument
- 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
- Need help writing loop to display posts by categories in separate divs
- Get posts by category or author
- Sort / Filter Queries
- get_page_by_title() not working if special characters are present
- Modify WordPress loop after it has been run
- I want to send push notification just after publish a new post
- Query post category & remove any post id
- show latest authors blog post
- get “read more” with custom DB query like you would with WP Query
- How to get only current images of a post
- Ordering posts alphabetically by meta keys and title
- Why I obtain this WP_Query strange behavior trying to select posts having a specific tag?
- Why I have this strange behavior when I try to exlude the featured post from posts visualization?
- How do I control the fallback query after the original query returned cero posts?
- How to Test a Blog Post for Update vs. Publish Status — Unique
- Remove duplicated posts in the loop if post has more than one category
- How to pass multiple checkbox values to wordpress query?
- Adding a category at even positions on main loop with modified pagination
- How to handle a post before publishing?
- How to limit the number of results for all query_posts on mysite
- How to get all post titles starting with numbers and symbols?
- How to inject a post within a loop
- How to get alphabetic listing x other posts, based on first letter post?
- wp_query select if have comments
- Creating pages and getting their values from the database table
- How to limit post query to only return a total count of items with certain post statuses?
- Not displaying any articles on a custom made file
- wp trim function not working
- 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
- Action while post is being published
- Change from all posts to specific categories post on main page?
- query_posts different amount of posts per page [duplicate]
- Count words for all posts by all authors
- Word count for all posts of all authors
- Do I need to create a multisite for querying posts from multiple WordPress sites?
- Dynamic archive of posts by date
- How can add custom commands in post-new.php in wordpress
- Sort Posts Alphabetically Based on Specific Category (Divi)
- How to change url of posts?
- It tells me that I exceeded the maximum number of executions when trying to publish content
- How to show related posts by detecting the current category?
- Display posts on a custom page from only a specific category?
- Why does ‘get_the_ID’ work outside of the loop?
- WordPress Post Query Using Custom native MySQL like St_Distance_Sphere
- How to add publish button in menu All Posts (Wp-Admin)