save_post action not firing when save

You have some errors in your code. For example, you unset a not defined variable. Some lines bellow you try to use again a not defined variable….maybe this is what is causing the problems. Can you try this? (Edited, I think is better get_posts than new WP_Query in this case) function wpse_update_postmeta($post_id) { if (defined(‘DOING_AUTOSAVE’) … Read more

How to change the post author when the post is published?

From the code you have posted there, it doesn’t look like, at any time, you’re are hooking the function on to save_post outside of your function. function change_pos_auth($post_id){ if ( ! wp_is_post_revision( $post_id ) ){ // unhook this function so it doesn’t loop infinitely remove_action(‘save_post’,’change_pos_auth’); if ( isset($_GET[‘auth_id’]) ) { $args = array(‘ID’=>$post_id,’post_author’=>$_GET[‘auth_id’]); // update … Read more

get categories the post was in and just been removed from

save_post runs too late to do what you are trying to do. That hook fires after the post and related meta data are stored. The category has already been removed at that point, and WordPress keeps no record. You will need to hook into the save process earlier, perhaps pre_post_update: add_action( ‘pre_post_update’, function($post_ID,$data) { var_dump($post_ID,$data); … Read more

Save data of select list after clicking save

You have the add_action that’s supposed to hook your prfx_meta_save function inside the function itself, so it never gets hooked or called. You need to move the add_action outside the function. This will never work: function prfx_meta_save( $post_id ) { add_action( ‘save_post’, ‘prfx_meta_save’ ); } Move it outside the function: function prfx_meta_save( $post_id ) { … Read more

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