Is there a before_save_post hook or something similar
There is a hook called transition_post_status which runs at every transition. You have both the old and new status available inside the hook.
There is a hook called transition_post_status which runs at every transition. You have both the old and new status available inside the hook.
A post can only ever have one parent post. I’m certain you can still accomplish what you want using post meta, though. If you give us a better explanation of what you’re trying to do we might be able to help. For example, function updating_parent() { // your code to get posts foreach ( $my_posts … Read more
I was able to find a solution by following the advice in this article (https://www.godaddy.com/community/Building-and-Managing-a-Website/fatal-error/td-p/31814): Open your hosting account, go to File manager and access this folder: wp-content Rename this file object-cache.php to object-cache-OLD.php As a developer I don’t know how to prevent this for future clients without a greater understanding. Comments and new answers … Read more
A two-part answer below – As above: the broad solution was to save the posts first as draft, then update them with the custom fields and terms, and only then set them to publish. As I said, the above code modification had succeeded in setting the posts to draft but not in transitioning them to … Read more
What was happening was, the global variable $post wasn’t ending up on the POST page – so in the conditional below where the form was being processes, if ( ‘POST’ == $_SERVER[‘REQUEST_METHOD’] && ! empty($_POST[‘post_id’]) && ! empty($_POST[‘post_title’]) && isset($_POST[‘postcontent’]) ) { header(‘Location: /’); $post_id = $post->ID; $post = array( ‘ID’ => esc_sql($post_id), ‘post_content’ => … Read more
check: https://codex.wordpress.org/Function_Reference/wp_update_post Make sure not to create an infinite loop. <?php function my_function( $post_id ){ if ( ! wp_is_post_revision( $post_id ) ){ // unhook this function so it doesn’t loop infinitely remove_action(‘save_post’, ‘my_function’); // update the post, which calls save_post again wp_update_post( $my_args ); // re-hook this function add_action(‘save_post’, ‘my_function’); } } add_action(‘save_post’, ‘my_function’); ?> … Read more
First things first In a wp_ajax_{action} or wp_ajax_nopriv_{action} callback, the global $post variable is by default a null because WordPress has not yet set it up. You can confirm it using a simple callback like so: add_action( ‘wp_ajax_test’, function(){ global $post; var_dump( $post ); wp_die(); } ); Visit /wp-admin/admin-ajax.php?action=test and you should see NULL displayed … Read more
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
Try to use wp_update_post() in place of wp_insert_post for update. $id = wp_exist_post_by_title($post[‘post_title’]); if($id !== false) { $post[‘ID’] = $id[“0”]; // Create Post $post_id = wp_update_post( $post ); } else { $post_id = wp_insert_post( $post ); }
When commenting out wp_update_post( $post ), the update_post_meta is working fine. Yes, the problem is not with update_post_meta(), but it is wp_update_post() because it uses wp_insert_post() which fires the save_post_foglalas hook (i.e. save_post_<post type>), and because your function calls wp_update_post(), then your function gets called infinitely and eventually caused the White Screen Of Death (WSOD). … Read more