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

Custom Meta Box (SELECT2) Not Saving Taxonomy Terms

First of all you saved the the terms value in a post meta table and not following the wordpress conventional method. To make it connect with default category with that post you need to modify your save_post action. Check the modified code. add_action( ‘save_post’, ‘rudr_save_metaboxdata’, 10, 2 ); function rudr_save_metaboxdata( $post_id, $post ) { if … Read more

Changing new post to “pending” on publish – but “Publish failed” – why?

The wp_update_post hook will call the same action twice, as the action save_post_{$post->post_type} is called in this function. I would add remove_action( ‘save_post_tribe_events’, ‘set_to_pending’); before wp_update_post( $post ); and add_action( ‘save_post_tribe_events’, ‘set_to_pending’, 10, 3 ); after it works 🙂 function set_to_pending($id, $post, $update){ $the_post = print_r($post, true); $the_post_author = $post->post_author; $the_post_url = get_edit_post_link($id); $the_post_url = … Read more

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