The $post
you’re working with is a WP_Post Object and you must interact with it as so.
$post->post_status="draft";
It’s usually not a good practice to modify the $post
object directly so it’s something you may want to avoid. A better way may be to simply pass an array of values to wp_update_post()
function like so:
wp_update_post( array(
'ID' => $post->ID,
'post_status' => 'draft',
) );
Related Posts:
- How to change “Draft” string for status of custom post type to “Unavailable”?
- How to enqueue scripts on custom post add/edit pages?
- remove custom post type permalink
- New post status for custom post type
- Action hook on Edit custom post type?
- Unregister post type from child theme
- Custom post type save_post action not firing
- Why The Init Hook For Custom Post Types
- How to show more posts on an archive page?
- Restrict a Post Types Post Status
- Customize users’ capabilities to change a custom post’s post status
- With what hook can I address all posts from all custom post types when they are published?
- Custom Post Status not showing in Custom Post Type ALL view
- Make the ‘all’ filter default instead of ‘mine’ in a custom post type
- Dynamically Create Terms in Taxonomy when Custom Post Type is Published. Almost There!
- WordPress Custom Shortcode Conflicting with Media Library
- WordPress custom post action hook
- action init hook and get_post_types
- delete custom post based on custom field date
- wp_publish_post breaks permalinks
- Custom post type archive sorted and grouped by date in post meta field
- How do I check if a posts status is set to draft or pending?
- pre get posts changing the query
- How to register custom post types in a plugin?
- Actions that Run on Admin Edit Page Load After Posts Are Queried
- How to set default status to custom post type
- Using pre_get_posts to Filter Posts
- Remove “Get Shortlink” button in admin of custom post type
- Posts created in a Custom Post Type are lost if published without a title
- How to get Custom Post ID by adding filter to child theme’s function
- Custom post_type search’s $wp_query->query_vars do not correspond
- Registration and Custom Post Types – How to synchronize information?
- Check Title Unique Or Not and If not error message and dont save
- 1 day after custom date change post status to draft
- Can’t unregister parent theme’s CPT from my child theme
- Add html to cpt main page / admin edit.php
- register_taxonomy and register_post_type does not work [closed]
- Auto-generated posts not showing in backend (but being counted!)
- How to limit post of custom post status?
- How to: Display ACF [fields] on Custom Post Types Utilising WordPress ‘Hooks’? [closed]
- Custom post type unintentionally called in every page
- Trigger email send after custom post publish
- Displaying custom taxonomy in the admin list of a custom post type
- Can taxonomies of custom post types be used with category actions?
- Changing wordpress publication date to ACF date and time picker date not working
- A method for ordering mixed dates in search result loop (theory only, no actual code)
- How do I add a custom screen for a custom post type to be called from custom post row action?
- Update postmeta Parent when post_status child change
- “Submit for review” for updates on existing posts
- Removing all post statuses from a Custom Post Type
- Add custom post type drafts to RSS feed
- Filter Posts from the Main Query
- How can I move (or create another) publish button?
- Can’t publish custom post type – “You are not allowed to edit this post.”
- Using preg_replace to filter custom textarea
- Create new custom post and post category of same name
- Get only used meta_values
- Programmatically change post visibility on save_post action return a 500
- Include php on a specific page template
- wp_trash_post action hook with custom post type
- Custom Meta Box Causing Error: “Are you sure you want to do this? Please try again.”
- What do the numbers mean at the end of add_action(‘save_post’)…?
- Running a wordpress action when a custom post type term (taxonomy category) is changed
- Published post auto change status to pending after 90 days
- Types plugin custom post add_action hooks
- Loading plugin text domain before registering post type
- How can I get some of a posts meta data whilst it is still inserting?
- How to recover the post ID earlier in the WP admin hook action “firing” sequence?
- Manually adding or updating CPT automatically sets post_status of future
- Change user role when user’s first post gets published
- Publish box in CPT remove ‘edit’ link
- Using `set_transient()` when saving a custom post type
- Using publish_{custom-post-type} hook for custom post type to update meta doesn’t work
- Set Post Private if no linked Post Objects (ACF)
- Update main post with same category when creating custom post to update the modified date
- Show custom post status when logged out
- How to hide private posts even if user is admin
- Modify Publish Metabox location on CPT
- Update post status from “publish” to “trash” prior to year 2018
- edit.php all post not working
- publish_post action callback not executed, why?
- Sql Update CPT from publish to draft and particular custom field
- Custom Post Status not getting displayed after post update
- How to store additional data that is related to core data
- Custom status and permalinks don’t work?
- How to save post_status using action save_post?
- Keep br tags from stripping
- ACF saving posts
- Implement post status update as frontend news announcement
- date archive future posts
- Publish post and create additional posts with same content
- Disable Facebook Comments Automatically On CPT
- Custom Post Status & Taxonomies
- Updating User Meta from Custom Post Field Upon Publish Not Working
- What is the proper way implement a global $wp_rewrite?
- Dynamically change post_parent in every page load?
- Create action running on trashed_post hook to modify post_meta value
- Custom post type functions.php if statement on action
- Emailing Authors only when a CUSTOM POST TYPE post is published- not when edited later [duplicate]
- Comments not working (error not allowed) on posts with custom post status