Quantcast
Channel: Check for update vs new post on save_post action - WordPress Development Stack Exchange
Browsing latest articles
Browse All 12 View Live

Answer by Nejmeddine Jammeli for Check for update vs new post on save_post...

here is a functional code that worked and tested by me i used in my website also it solve the two following problem associated with save_post action :problem to check between ubdate or insertproblem of...

View Article



Answer by wpclevel for Check for update vs new post on save_post action

Since the $update param is useless, this is the fastest way I tested:function wpse48678_check_is_post_new($post_id, $post, $update){ if (false !== strpos($_POST['_wp_http_referer'], 'post-new.php')) {...

View Article

Answer by 西門正 Code Guy for Check for update vs new post on save_post action

I have just encountered the save_post about new and update. After reading the source code to understand the flow. I found that the following method might be useful. Since it is not yet mentioned...

View Article

Answer by Goran Jakovljevic for Check for update vs new post on save_post action

Example to ialocin answer with "update" paremeter:function save_func($ID, $post,$update) { if($update == false) { // do something if its first time publish } else { // Do something if its update...

View Article

Answer by Nicolai Grossherr for Check for update vs new post on save_post action

Since WordPress version 3.7. - IIRC - the save_post hook - more information about the hook and its usage at Code Reference: save_post and Codex: save_post - has a third parameter $update which can be...

View Article


Answer by James Cushing for Check for update vs new post on save_post action

The way I perform this check (within a hooked function) is to compare the post date and modified date (in GMT for standardisation)function check_new_vs_update( $post_id ){ $myPost = get_post($post_id);...

View Article

Answer by Qix - MONICA WAS MISTREATED for Check for update vs new post on...

As Darshan Thanki hinted (and Stephen Harris further elaborated), you can use pre_post_update to your advantage.global $___new_post;$___new_post = true;add_action('pre_post_update', function() { global...

View Article

Answer by John112 for Check for update vs new post on save_post action

Another approach that uses a built-in function and no addition to the database would involve get_post_status().$post_status = get_post_status();if ( $post_status != 'draft' ) { //draft} else { //not a...

View Article


Answer by Darshan Thanki for Check for update vs new post on save_post action

You can use pre_post_update action hook for the update code and save_post for the new post code. It works before a post is updated.

View Article


Answer by hereswhatidid for Check for update vs new post on save_post action

I ended up just checking for the existence of a custom value prior to setting it. That way, if it's a newly created post the custom value would not yet exist.function attributes_save_postdata($post_id)...

View Article

Answer by moraleida for Check for update vs new post on save_post action

When save_post is triggered, all information about that post is already available, so in theory you could usefunction f4553265_check_post() { if (!get_posts($post_id)) { // if this is a new post...

View Article

Check for update vs new post on save_post action

Is it possible within the save_post action to determine whether it's a new post being created or an existing post being update?

View Article
Browsing latest articles
Browse All 12 View Live




Latest Images