You hook a function to save_post (for saves and updates) or publish_post for publication only. The second hook is really a variable hook of the form {$new_status}_{$post->post_type} so it will be different if you aren’t dealing with a post post type.
function do_on_publish_wpse_98177($id) {
// your code; $id is the post ID
}
add_action('publish_post','do_on_publish_wpse_98177');
Make backups and test thoroughly on a development server. It is easy to break things with these hooks.
You can use $id to pull information from the database including category information. You can also access the global $_POST if you need it but these hooks run after the post save so if something has altered (another function) the data saved to the database $_POST might be out of sync.
See also:
Related Posts:
- Accessing post’s meta data based on user’s click of a post
- Redirect to another page using contact form 7? [closed]
- Creating two database tables via plugin
- WP_query parameters for date range
- How Do I Use The WordPress Plugin Posts 2 Posts by Scribu?
- insert data in database table from plugin with WP3.1
- Custom database or Custom Post Types?
- How to extract images of post and pages excluding header and logo image in wordpress?
- Get the last post ID
- Enable comments for post with comments meta box removed
- How to count number of records found in a database table?
- Custom Post Type causes Page Not Found
- How use %like% in sql statement wordpress
- Is there a way to order posts and custom post types as one group?
- How can i list random post from multiple category?
- how do i remove posts from a WP_Query so the pagination is right?
- Saving Custom Post types and fields to a custom table
- How do I “get the next 10 posts after post_id == x”?
- Is it possible to create Custom Post plug-in?
- get_post_type on post.php
- DROP TABLE with uninstall hook not working
- Matching Chapters to a Custom posts [closed]
- ACF: post query, hide duplicate values [closed]
- How to delete all trashed item in one-go
- Custom setup of wordpress comments that are displayed
- Problem of encoding characters (apostrophes) in my posts publications
- Making my plugin create a page?
- posts from multiple post types in one slider
- How to relate 3 wordpress components with each other (Create database relationships)
- Show related posts based of current ACF field name in a single page post (a loop within loop)
- How can I store data from custom fields to custom tables?
- Custom Template for wordpress cpt plugin
- What hook can I use to modify custom post data before it is displayed on the page?
- Delete data from custom table when deleting a post
- Is it possible to pin a post in second position from top
- How to search post titles with whole words only, but not the exact word only?
- What database state changes happen after a post is manually “updated” with no changes?
- Can i stream data to a custom_post_type?
- Is there a hook similar to “save_post” which only fires AFTER the post is completely published?
- Adding custom post category to categories widget
- How to display the custom post related blog by category?
- WordPress hide post from custom post-type on a single page
- $wpdb->insert not working inside save_post tag
- Is it possible to customize a wordpress post from outside dashboard(Something like site.com/post-type/post/?e=post_id)?
- Trending Tags based on post views
- WordPress list child pages of custom post type
- WordPress custom posttype meta values doesnot save
- Ger posts from similar tags and categories
- Posts are deleted everyday at night
- wpdb get_var is not returning any result (verified mysql query returns only one value)
- WordPress ultra slow if I click on posts?
- Making a Custom Post Type Publish Loop
- Shortcode returning specific content of a post
- How to export post tags from wordpress
- What is the easiest way to create a custom field archive?
- Show the author only own types of publications. (JetEngine, Elementor)
- How to check if the post exists in any of the categories?
- Plugins or Tutorials for displaying data from SQL-db on WP-page? [closed]
- Can I explicitly specify ENGINE=InnoDB in WordPress?
- Unique post-id for WordPress Multisite Network
- CKEditor: Uncaught TypeError: switchEditors.switchto is not a functiononclick
- custom taxonomy and custom post type url conflict
- Make id column as AUTO INCREMENT on plugin activation
- WP_Query ordering numbers as letters
- Execute a plugin only on post pages
- Display by Category in Admin
- WPDB: Update table
- Import Instagram post to WordPress blog post
- WP_Query with custom post type ID
- Add some fileds to the wp_posts table
- How can I automatically download all images from all imported posts, place them on my new host, and replace all the links
- Always get creating a new table with foreign key
- How to get CPT category checkbox list and show post of selected(multiply) checkboxes via ajax?
- Preview with Custom Post Type Not Working
- If post exists in the database – each time goes on `else`
- How can i summerize posts or news automatically in word press site?
- Custom Post Type template for homepage
- Edit part of a post
- Best method of implementing compartmentalized custom post types on a multi-site network
- Help to Create a Simple Plugin to make a post
- How to Join wp_posts & wp_postmeta table using custom query
- Randomize post (and page) IDs on generation
- Moving all wordpress posts from 50 websites to another website
- add tags to wordpress post using REST API
- How to make a page both “private” and “password protected”
- Failed to load resource: the server responded with a status of 500 () post.php
- My plugin can’t see my files
- Custom post type request switches to media request
- Custom Post Types and Posts are mixed
- Retrieving IDs of child pages which are in a different post type
- Custom Post type plugin breaking the front page shows dashboard?
- WP-Snap too slow (caused by WP_Query?)
- WordPress Meta Query: Relation is not working correctly
- Updating WordPress [closed]
- Looking for a plugins for organization portal (Staff, Units, Departments)? [closed]
- Notifications Bar on home page only
- Wrong block appender button showing
- Select posts from list and add them in a new list
- plugin doesn’t retrieve data from database
- PHP Fatal error: Cannot redeclare distance() when making a new block