You could also hook into the save_{$post_type}
action, which fires only when a certain post type is updated. This hook passes to post’s ID to the callback function:
add_action( 'save_post', 'my_callback_function' );
function my_callback_function( $post_id ){
if ( ! wp_is_post_revision( $post_id ) ){
// Unhook this function so it doesn't loop infinitely
remove_action('save_post', 'my_callback_function');
// Update post's data
$post = array(
'ID' => $post_id,
'post_date' => current_time( 'mysql' ),
'post_date_gmt' => current_time( 'mysql', 1 ),
);
// Update the post, which calls save_post again
wp_update_post( $post );
// Re-hook this function
add_action('save_post', 'my_callback_function');
}
}
Related Posts:
- Elegant way to include only published posts with get_objects_in_term()?
- Prevent scheduled post being published if date/time is past current date/time
- WordPress bulk category select when publishing post
- Get Posts Under Custom Taxonomy
- add action only on post publish – not update
- How to prevent posts from being published too close to each other?
- Different post sort order within different categories
- Is it possible to Schedule Attachments in WordPress?
- Displaying the category name of a custom post type
- How to schedule multiple posts while adding new
- Show WordPress Custom Taxonomy Items Based On a Selected Item From Another Custom Taxonomy
- order posts by date like craigslist
- Exclude posts that only have the ‘Uncategorized’ category [duplicate]
- WordPress plugin to publish to multiple remote WordPress blogs
- Post publish only hook?
- Publish pending article from front end with a button?
- How to add a “publish” link to the quick actions
- How are terms connected with posts in database?
- How to limit user to publish post per day and per role?
- When a user creates a post (pending), send a confirmation link that allows them to publish
- In what sequence are the hooks fired when a post is “published”?
- Convert IPTC keywords to blog post tags
- Restrict the Number of Posts an Author can Publish (over time)?
- Add javascript when post is published
- featuring old articles without messing up with the archive
- Show Custom Taxonomy Categories, Listing of Posts, and Single Post via AJAX
- Importing data from spreadsheet into wordpress DB, along with custom taxonomies and their terms
- Publish posts only after the condition is met
- Hiding by default specific post status on backend list?
- Detect Post Type when publish_post is ran
- get_terms parent for current product only
- How can I display a specific user’s first published post?
- deleting terms programmatically
- Does WordPress remove draft status automatically?
- What Can I Use To Add A Custom Button Between Publish button and Move To Trash?
- Prevent post from being published if no category selected
- Send email to user that his post has been rejected
- Adding Multiple Values to a Post Meta Key
- How do I get the slug of a custom taxonomy category of a post?
- How to get the latest posting time of archived pages in WordPress?
- Limit number of posts a user can make per minute?
- Post taxonomy from exif data
- Redirection to taxonomy posts list after post submit.
- Remove custom posts that match taxonomy value
- Using Custom Posts with Metaboxes and Drop-downs
- How to insert current date/time in the content of a post?
- Does an action fire when adding a tag via the “Tags” meta box?
- Every possible way to get data (posts) from WordPress
- publish_post conflicts with save_post
- How can I add a meta-box to the posts editor containing all items of a custom taxonomy as checkbox?
- How to get the date of a post in WordPress, so I could use it in a script?
- disable column on post and user list
- Notification to Admin or Author upon new post [duplicate]
- What differences are there between a Privately Published post and a Draft post?
- How to run a function when post is edited or updated using publish post action?
- How can I create custom button in post.php
- How to rename “Publish” metabox title in post screen
- count the total number of comments the user has received for his published posts
- Avoid duplicate post from same Taxonomy
- Get posts by name and taxonomy term
- How can I schedule a PAGE to go live at a future date/time?
- How to display data in archive page?
- How can I show many posts an author has per week?
- Set terms in a custom post
- How to give capability (publish contributors posts) to author role?
- Get posts of ONE taxonomy term of custom post type
- If modified on same day, show only time
- Pass data between pages
- Print a message if excerpt is empty after posts have been publish/update!
- Choose whether to automatically add a taxonomy with the same name as the post
- Display tag image in post using Taxonomy Images plugin index.php
- wp_get_object_terms returns only Uncategorized on first publish
- Setting posts_per_page for taxonomy term template
- Check if checkbox is marked on publish/update post
- How to bulk-untag multiple posts?
- Force the “Choose from the most used tags” meta box section to always be expanded
- Decide user that can publish a post
- How to switch wordpress post status between publish and schedule in MySQL?
- Posts list in custom taxonomy
- How to Restrict Previous & Next Post Link to Posts of Same Category?
- Get Posts Under Custom Taxonomy
- Prepending %category% onto default posts fails
- get_adjacent_post by language
- Automatically add date to the auto generation of post slug
- Duplicate Custom Post Type and Taxonomy Slug
- Remove Custom Post Type Slug and add Custom Taxonomy to Permalink Structure?
- Calling Different Custom Post Timestamps in a table
- How can I setup a relationship using categories in WordPress?
- How to display posts via custom taxonomy terms using checkboxes?
- How can I hide tags on a child-category page, if that tag has not been used?
- Copy post to separate database with “add_action(….)”
- 404 error on default post type and default taxonomy fronted page
- How i can limit period of post publication?
- Do action on publish or update?
- transition_post_status hook doesn’t have any POST data when publish with Gutenberg [closed]
- How do I manage my users post before publish?
- How do I insert a post with custom post type and relate it to a custom taxonomy?
- do more action after I publish a post
- outputting posts’ taxonomies: cant get ‘get_the_taxonomies’ working
- Loop parent terms {display posts} AND loop child terms {display posts}