Check if the value of a field has changed on save_post

Usually there is no way to check if the meta data is updated or not, but you can use updated_postmeta and added_post_meta to get kinda similar functionality. Please have a look at the below code- add_action( ‘updated_postmeta’, ‘the_dramatist_updated_postmeta’, 10, 4 ); add_action( ‘added_post_meta’, ‘the_dramatist_updated_postmeta’, 10, 4 ); function the_dramatist_updated_postmeta( $meta_id, $object_id, $meta_key, $meta_value ) { … Read more

WordPress Gutenberg get page template value when post updated?

So I found a solution. There are 4 hooks that can be used to accomplish this depending on the exact needs. The hooks are from wp-includes/meta.php in functions update_metadata() and add_metadata(). Hooks: update_postmeta updated_postmeta add_post_meta added_post_meta These are called at different states and from the names it is pretty self self explanatory. add_post_meta and update_postmeta … Read more

Exclude trash from save_post

save_post gets fired, once the post is saved. We get the current post object as the second parameter. So we can check, if the current post status is trash: <?php add_action( ‘save_post’, function( $post_ID, $post, $update ) { if ( ‘trash’ === $post->post_status ) { return; } /** do your stuff **/ }, 10, 3 … Read more

Get the post_id of a new post

Try this… add_action(‘post_updated’, ‘myfunction’); function myfunction( $post_id ) { global $post; if (!file_exists(“/www/foo/blog/wp-content/uploads/” . $post_id)) { mkdir(“/www/foo/blog/wp-content/uploads/” . $post_id, 0777); } } NOTE: Change from save_posts to post_updated which will stop the duplicate issue as it fires on “publish” only and not every time you hit add new or update etc. NOTE: I verified this … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)