But I am having an issue, described as follows:
// Inside the save_post attached callback $arg = array( 'ID' => $post_id, 'post_author' => $whoever, ); wp_update_post($arg); --> This fires the save_post hook --> Infinite loop
This is a special case in which I need to do the update inside the save_post callback. This results in an infinite loop. (See this similar case)
I wonder if there is an alternative way to update a post author that does not fire the save_post hook.
I know I could use the builtin author metabox for this, but the requirements push me to not use the builtin author metabox, and I must use a custom metabox to update the post author.
A possible solution is using SQL directly:
UPDATE `wp_posts` SET `post_author` = 2 WHERE `ID` = 1
Which could be implemented with:
global $wpdb; $wpdb->get_results("UPDATE `wp_posts` SET `post_author` = " . $int_author . " WHERE `ID` = " . $int_ID);
Of course previously making sure that both variables contain numbers.
Does anybody know a better solution?