How is this possible?
I can think of one possibility that for some reason ur page is getting auto reloaded. So the flow of execution is like: you access the page, your code gets executed changing status from draft to published, then some other code gets executed and the page is reloaded. This time when your code gets executed it sees the post is already published and outputs the msg accordingly.
Along with echo statements try using error_log
as well and see what you get in the log.
Also you can check developer tools > network tab in your browser if the page is getting auto reloaded or not.
Related Posts:
- wp_update_post() example… how to update the_content in a textarea?
- Why wp_update_post() does not update GUID?
- What are the limitations of wp_update_post()?
- I need to bulk update all wordpress posts on a scheduled time
- wp_update_post does not update post_name
- How to disable saving/changing update date for certain admin users?
- “Internal Server Error” with wp_update_post
- wp_update_post using post_name
- how to get last revision id created after wp_update_post
- why wp_update_post cant update when value is empty?
- update a post with wp_update_post
- Updating posts not working
- Update a post’s info when clicking on a javascript button
- What ‘function’ will ‘update’ a post?
- wp_update_post meta causing 500 error
- Updating post_parent by id (many times)
- wp_update_post making my post sticky
- Is it possible to “Update” pages via SQL?
- Update post meta is slow while saving post
- Update post (published) date when changing category
- recursively update content
- $wpdb->update query incrementing value on it’s own!
- Update button (sometimes) greyed-out
- Set a post to draft once depending on a post meta value (passed certain date)?
- wp_update_post behaves differently for different user role
- Fatal error: Call to undefined function wp_cache_get after update attempt
- How to avoid infinite loop in save_post callback
- Programatically change post author
- wordpress function to change post status [duplicate]
- Post/Page Publish/Update button not clickable once I make an edit
- Issue with wp_insert_post and post_content field error Could not update post in the database
- Which action hook can I use when a featured image has been selected
- How to batch update post content with custom post meta value
- Scheduling posts to update once per day with wp_cron
- Fill post titles from post content?
- Keeping post_date same as the pending post_date on privately publishing the post
- SQL query to update post_date (one post = one single date & time)
- How can I stop wp_update_post messing up HTML example code?
- Update post date on every new comment?
- What action hook updates post meta?
- bulk post_content update
- wp_update_post on specific custom post type
- Mass Update lines of code for all posts
- Unable to modify(update) posts – Page not found
- How to check if wp_update_post was successful
- Automatically insert php function into post $the_content
- How trigger to save post when updating post meta
- Problem with wp_update_post
- What’s the proper way to use a custom table? [closed]
- post_status => publish not working
- Adding action to save_post, post needs to be saved twice for function to work
- Change the post date from a meta box
- How to show Published date and/or Modified date
- Display success message after wp_update_post
- Function to change post status IF current user and post author are the same
- wp_insert_post_data filter hook identify current action
- Update post title with category name after editing a category
- Posts are duplicating on wp_post_update
- custom post scheduler for drafts
- If modified on same day, show only time
- List taxonomy terms for post as checkboxes
- How to bulk edit image url in featured image and product description?
- How to update all posts but the current one (post__not_in not working?)
- wp_update_post() blank screen
- Set post_parent value for the images uploaded by Add Media button into post
- Post author for revision not being set on update/insert
- wp_update_post via ajax from frontend
- Clear cache on post of one type when something happens to post of other type
- wp_update_post is not updating category
- Inline style HTML attribute is being stripped from all elements of a post
- wp_update_post onclick button using ajax
- Programmatically change post visibility on save_post action return a 500
- Gravity forms and wp_update_post [closed]
- Why does wp_update_post causes white screen?
- Custom Meta Box (SELECT2) Not Saving Taxonomy Terms
- Update status, meta while inside a post using AJAX button
- Can’t update WordPress Page if post_content is Empty
- Odd behaviour for the update button when displaying a WP_List_Table
- Update Custom Taxonomy Value for a post based on custom date field
- Custom wp_editor doesn’t update post_content
- How to keep a record of changes to a custom field?
- The work of WordPress Function update_post
- Trash Bin for Categories?
- Prevent other hooks from firing after wp_update_post() outside of editor
- Set post publish date by custom field
- Run a function when a custom post is update?
- wp_insert_post($post), add an array of values with update_post_meta
- How can I trigger a javascript function after a post update on edit post screen in wordpress admin panel?
- Update around 200,000 posts
- Cannot update page – with too many characters?
- update flamingo_inbound post type after insert
- wp_update_post to set post IDs to drafts not working
- Front Page post mirroring revisions to other pages, constantly updating itself
- set_post_format called after wp_update_post when using bulk edit?
- Auto draft posts when scheduled date is reached
- Change custom post status to draft before today
- Setting a featured image while creating the post
- How to create posts with a specific date in bulk
- Update Post with Modified Data
- Bulk post approval and publishing doesn’t work