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
- Is it possible to define a template for a custom post type within a plugin independent of the active theme?
- What are these entries in the database? Looks similar to JSON
- How to create a Page alias in WordPress
- Comparisson between date() and a date from wp_postmeta
- How to filter content post only on save
- How to edit/delete single row items in a table on my own menu page
- Is there plugin to show recent posts from one website in the widget area of another?
- FacetWP group listings by custom field [closed]
- Why get_posts() not returning only selected category posts from Custom Post Type?
- Doubt using $wpbd->get_col for a single column
- submit posts by unregistered users in wordpress
- WordPress Settings Lost After Site Migration
- Two problems on my WordPress installation [closed]
- How to pull email and name from Flamingo plugin
- Which widget to use for display category post with view more? [closed]
- Is it possible to store Custom Post Type data in separate set of tables and still have wp_post class functionality?
- Prioritize posts in query by meta keys?
- Unable to delete custom post types, confusion around capabilities
- How to create multiple database tables on plugin activation?
- after wordpress update to 3.5+ i get many errors in plugin wpdb::prepare()
- How can I use a file in my plugin as a replacement for single.php on custom-post-type query?
- How to set category correctly for a custom post created by a remote API call?
- Moving FB comments at the end of page
- BuddyPress activity on edit post for a CPT
- I would like to remove date display on photo preview
- Get data from wp_posts of mysql in to variables of wordpress-php script
- Problem with ajax plugin for refreshing posts
- Add posts from other WordPress blog to the current one
- How to create repeater field manually, without plugin (ACF Pro)?
- How to get specific column data conditionally in database in WordPress?
- Right way to store a large set of similar information on website? [duplicate]
- Store GravityForm data in phpmyadmin (mysql)
- Pagination (including title of each page) in a post for a long posts
- Database error when user logs in
- Include post_date in search
- Add Filter to get_next_posts_link
- Action hook “wp_insert_post” works but not for last imported post
- Capturing POST data
- Top Contributors Plugin with Custom Post Type
- How to submit the custom form data in database in WordPress without plugin?
- How to hide home title on pages and posts?
- Is it possible to recover Deleted users?
- Windows 10 Printer that Sends to WordPress [closed]
- Order custom post type by posts with most likes first
- Getting 400 Error in wordpress website
- How to provide page_template path in custom plugin using WordPress