Compare custom taxonomies of updated post (or new post) [Updated with progress]

Use the set_object_terms hook, http://adambrown.info/p/wp_hooks/hook/set_object_terms?version=3.4&file=wp-includes/taxonomy.php It should be fired when a post or page is modified. Here is the code that fires it: do_action(‘set_object_terms’, $object_id, $terms, $tt_ids, $taxonomy, $append, $old_tt_ids); You can thus check against the $object_id and taxonomy, and flush your transient cache and regenerate as needed. Specifically, clear the term caches of the … Read more

What’s the proper way to sanitize checkbox value sent to the database

I would use the filter_var() function. It has some predefined filters that you can use depending on what kind of data you are expecting such as string, number, etc. So to sanitize for a number: $sanitizedNum = filter_var($yourVar, FILTER_SANITIZE_NUMBER_INT); For a string you would just change “_NUM_INT” to “_STRING”. Wrap those in a custom function … Read more

Why not fire the save_post event?

The save_post action hook fires after a post is saved: every time, even for autosaves. If you look at the reference for save_post, you’ll see that the callback receives three parameters: the first is an integer $post_ID, the second is a WP_Post object $post, and the third is a boolean $update. None of the parameters … Read more

Save values from a pre_post_update

The second attempt is closer to the result, as it is filer, not action, and you can return proper data. But code has several mistakes, I have fixed them. The proper number of parameters for the filter is 3. The first parameter is $data which should be modified and returned. It is the standard behaviour … Read more

Conditional for autosave or auto draft?

If you are using the save_post action hook; then you can prevent the code from executing during an autosave with the following conditional: function do_not_autosave( $post ) { // Check to see if we are autosaving if (defined(‘DOING_AUTOSAVE’) && DOING_AUTOSAVE) return; // Rest of the code here } add_action( ‘save_post’, ‘do_not_autosave’);

WordPress function saves a post twice and updates all posts

It duplicate because when you run the wp_update_post(), it will use the wp_insert_post() function and the action save_post will run again. please use the filter wp_insert_post_data to filter the value before save. https://codex.wordpress.org/Plugin_API/Filter_Reference/wp_insert_post_data Example: function wpse309780_filter_post_data($data , $postarr) { $data[‘post_name’] = wp_count_posts( ‘post’ )->publish; return $data; } add_filter( ‘wp_insert_post_data’, ‘wpse309780_filter_post_data’ );

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