Updating post data on save (save_post vs wp_insert_post_data)

At first, Data was sanitized here (line 2997). If you don’t want any plugin/theme run on action save_post. User function remove_all_actions to remove all functions hooked to action save_post. function post_save_action($post_id, $post, $update) { if ($this->is_temp_saving_post($post, $post_id)) { return; } // Check user permissions if (!current_user_can(‘edit_post’, $post_id)) return; // Update post if (!$this->is_proper_post_type($post)) { return; … Read more

How to inform the user that the save was not successful?

Handling admin notice on Edit Post When action related to post or editpost, we will be faced with redirect_post function. There are two filters you can use to handle the post messages, redirect_post_location and post_updated_messages ( see the list messages at https://core.trac.wordpress.org/browser/tags/4.8/src/wp-admin/edit-form-advanced.php#L135 ). Here the sample code how to handle the messages. Create new message … Read more

Add category only if post has custom taxonomy category

wp_get_post_terms( $post_id, $taxonomy, $args ) expects third param to be an array of arguments. Params $post_id (integer) (optional) The Post ID Default: 0 $taxonomy (string|array) (optional) The taxonomy for which to retrieve terms. Defaults to post_tag. Default: ‘post_tag’ $args (array) (optional) Overwrite the defaults Default: array My guess is that $old_term is being set to … Read more

How to change image atributes right before an image to be saved?

If the import function you’re using uses wp_insert_post() (used also by wp_insert_attachment()) to add the new images (attachment posts) to your site, then you could perhaps use the wp_insert_attachment_data( array $data, array $postarr ) filter, which is defined inside wp_insert_post(). According to the docs it, Filters attachment post data before it is updated in or … Read more