Create post revision on slug change

If you’re comfortable with PHP, it would be possible to keep track of when the slug is updated. The only way I can think of is a bit complicated: Make sure revisions are enabled, both for your install and for the post type you’re targeting. You’ll have to determine how many revisions you want to … Read more

Bug: Post needs to be updated twice when adding action for save_post hook

You’re doing several things wrong, and they’re all silly, avoidable, basic logic mistakes. Firstly, you’re not checking if this is an autosave. Autosaves do not save the custom fields, only the original core wordpress fields, like content, so an autosave will giv eyou unset/blank values. Add this to the top of your save function: if … Read more

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