save_post not triggered when a post is updated

A var_dump() in save_post action doesn’t display any information on the screen. Well, it does only when you are on “Add new” screen. This is due the different sequence of actions that follow when creating a new post or when editing it. When you click on “publish” or “update” button, there is a request, the … Read more

Stripping URLs & Email from post submissions

You can use the_content (Click here for more info) hook to change the content while rendering the post/page. This will be triggered when Post is being read from Database. So post content will not be changed in database but only filtered while rendering. add_filter( ‘the_content’, ‘remove_email_and_url_from_post’ ); function remove_email_and_url_from_post( $content ) { // Check if … Read more

Dynamically set taxonomy term and show admin notice on post save

Okay, so just in case anyone needs help on the same thing I did… here is my solution. Instead of a php/wordpress solution, I used javascript. Id love to see the php/wordpress solution if someone wants to post it. <?php // Admin Custom JS add_action(‘admin_head’, ‘admin_custom_js’); function admin_custom_js() { ?> <script> // update date (month) … Read more

Can’t add_action to ‘save_post’ and get it to fire

When editing a post using the admin interface the wp-admin/post.php script redirects you after saving the post. This is done to avoid resubmitting the post request if you refresh the page after submitting. It also means that you’re not able to output anything during the save_post action. case ‘editpost’: check_admin_referer(‘update-post_’ . $post_id); $post_id = edit_post(); … Read more

Run a function on all posts

Rather than hooking into init or wp_load, here is a snippet you can drop into functions.php or on a theme file. I put it behind a $_GET so that you can only hit it once and when you are ready. Something like https://domain.com/page/?update_post_meta // Hide it from the public if(isset($_GET[‘update_post_meta’])){ // Let’s query all of … Read more