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 ArticleAnswer 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 ArticleAnswer 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 ArticleAnswer 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 ArticleAnswer 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 ArticleAnswer 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 ArticleAnswer 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 ArticleAnswer 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 ArticleAnswer 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 ArticleAnswer 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 ArticleAnswer 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 ArticleCheck 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
More Pages to Explore .....