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)
- Disable All In One SEO plugin for custom post type
- How to check if the post exists in any of the categories?
- Query Custom Post Types on Available Dates
- Tips for using WordPress as a CMS? [closed]
- Adding a Taxonomy Filter to Admin List for a Custom Post Type?
- Custom Post Type Templates from Plugin Folder?
- Manually set global $post vars with an ID, in order to use template tags
- How do I show data from gravity forms in my template? [closed]
- Show a different number of posts per page depending on context (e.g., homepage, search, archive)
- Implementing a CrunchBase.com Clone using WordPress?
- Delete tables from database when deleting plugin
- Custom media upload content for inserting custom post shortcode
- Is it bad practice to create own table for a plugin?
- How to Add an Index to Plugin Database table
- How can I delete orphan keys in WordPress database tables?
- Redesigning Custom Post Type “Add New” page
- Is there a plugin that will override the “Error establishing a database connection” message? [closed]
- How to Remove Certain Screen Options and Meta Boxes from add/edit post type?
- How to prevent a post from being deleted?
- How to delete all records from or empty a custom database table?
- How to share category taxonomy with custom post type (The Event Calendar plugin)
- Is it possible to define a template for a custom post type within a plugin independent of the active theme?
- Include theme header and footer in custom plugin
- How to fetch WordPress Gallery Images to a Custom Post Type?
- How to disallow users to edit other’s posts for a new custom post type?
- Import posts from a different database with the same old id
- How do I set WordPress to send 2 different emails based on criteria in the database when someone submits a form?
- Randomly display activity posts on home page with buddypress
- Updating post_parent caused the website to become unresponsive for 40 seconds or more
- This is a plugin code that supposed to add badge/label Infront of post title but i don’t understand why it is showing the code tags in frontend
- Remove H1 title in admin post edit screen
- How to include Font Awesome icons into ‘menu_icon’ from register_post_type() function – wp admin?
- PHP Fatal error: Cannot redeclare distance() when making a new block
- How do I know if an archive correspond to a custom post type taxonomy?
- can not serialize and insert data from custom form
- Search result page admin panel – display values from the result’s metaboxes
- Keep the expansible tree (list of posts) open in the sidebar
- How to Display News in a Timeline with Headline, Category, and Time?
- Load a custom post type template.html from a plugin
- WP_Query for multiple post types just shows one
- How to show custom post type in all post section?
- How can you call to data in google sheet based on ID number?
- Shipping Refund via Stripe Creates New Order Instead of Updating Original Order
- Elementor: Exclude product categories when using “Source: Current Query”