Force post slug to be auto generated from title on save

The easiest workaround could be: function myplugin_update_slug( $data, $postarr ) { if ( ! in_array( $data[‘post_status’], array( ‘draft’, ‘pending’, ‘auto-draft’ ) ) ) { $data[‘post_name’] = sanitize_title( $data[‘post_title’] ); } return $data; } add_filter( ‘wp_insert_post_data’, ‘myplugin_update_slug’, 99, 2 );

Metabox with checkbox is not updating

Here is code I have used before – the main difference looks to me that you are checking if the meta exists rather than what it’s value is to determine if it should be checked. // Checkbox Meta add_action(“admin_init”, “checkbox_init”); function checkbox_init(){ add_meta_box(“checkbox”, “Checkbox”, “checkbox”, “post”, “normal”, “high”); } function checkbox(){ global $post; $custom = … Read more

How to avoid infinite loop in save_post callback

You can remove the callback from the save_post hook, update the post and then re-add the call back to the hook. The Codex gives an example. add_action(‘save_post’, ‘wpse51363_save_post’); function wpse51363_save_post($post_id) { //Check it’s not an auto save routine if ( defined(‘DOING_AUTOSAVE’) && DOING_AUTOSAVE ) return; //Perform permission checks! For example: if ( !current_user_can(‘edit_post’, $post_id) ) … Read more

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 used to determine just that. @param     int               $post_ID     Post ID. @param     WP_Post     $post          Post object. @param … Read more

Using save_post to replace the post’s title

This simplest method would be to edit the data at the point it’s inserted, rather than updating it afterwards, using wp_insert_post_data instead of save_post. This works on creating a new post or updating an existing post without change. It also avoids the danger of creating an infinite loop by triggering update_post within save_post. add_filter( ‘wp_insert_post_data’ … Read more

what is correct way to hook when update post

When a post is updated there are some hooks that are fired: ‘pre_post_update’ is an action fired just before the post is updated, the argument passed are 2: $post_ID and $data that is an array of all the other database colums of the post table ‘transition_post_status’ is an hook fired on update, and pass 3 … Read more

Why does save_post action fire when creating a new post?

When you click ‘New Post’, you’re simply loading the page wp-admin/post-new.php. In doing so, WordPress will always create a new post (an ‘Auto Draft’) to ensure all other features (such as media uploads) and plugins work as normal, even before you actually save a draft or publish the post. And this, in turn, triggers save_post. … Read more

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