Yes, it’s possible to loop all publish posts and change their post status to draft.
add_action('admin_init','wpse_244394');
function wpse_244394(){
$args = array('post_type'=> 'post',
'post_status' => 'publish',
'posts_per_page'=>-1
);
$published_posts = get_posts($args);
foreach($published_posts as $post_to_draft){
$query = array(
'ID' => $post_to_draft->ID,
'post_status' => 'draft',
);
wp_update_post( $query, true );
}
}
Related Posts:
- The next_posts_link() works only with original $wp_query
- Query *only* sticky posts
- Skipping first 3 posts in wp query
- Accessing the post content with WP_Query
- Get only modified posts
- How to output comments number of a post per day?
- Should ‘setup_postdata()’ be reset with ‘wp_reset_postdata()’?
- Replace Main Query With Custom Query
- Hide Post comments when displayed via WP_Query
- Group posts by year in loop
- posts_per_page doesnt work
- wp query with dynamic taxonomies and terms?
- Blogroll – Different layout for first post
- How do I use `posts_distinct` correctly?
- Automatic value for custom fields for posts
- Loop through all product posts?
- Improving WP_Query for performance when random posts are ordered
- Why won’t my taxonomy query show up?
- Get random posts between specific dates / of specific age
- How to find what index page a post is on?
- Get Posts that are in the current month or later
- WP Query to Get Array of Slugs
- WP_Query with ajax handler returns the same posts
- Why WP_Query(‘showposts=5’) shows only 1 post?
- How can I sort posts by the date and a custom meta field?
- Hiding Draft Post In Admin
- How to insert 2 args into 1 Wp_Query for a slideshow
- How to verify wp user password by sql query in wp? [closed]
- WP Query – Posts Per Page not working in combination with category__in
- How to return another post than requested
- Lost draft under all posts and drafts
- Get user categories with most posts in it
- posts_per_page option limits the number of Gallery items
- wp_query random post
- how to get post order by post id wp_query?
- Possible to alternate between two loops
- Nested WP_Query breaking loop
- How to display all posts divided/ordered by post date? [closed]
- Is it possible to use WP_Query to only pull posts with attachments?
- Every second post different class in blog view
- Get posts with multiple categories
- Do not show children of a category
- Display posts of specific category term
- Can’t understand why sometimes a [caption] field appears
- Display current post position in Elementor Posts widget
- Why in my query is display two title?
- wp_query with ajax
- How to give classname to post if post has no content?
- Custom wp-query in wordpress rest api
- posts_per_page returning only one post
- Need to know custom code to display random and most viewed posts in wordpress posts and pages
- How to retrieve certain number of images from a wordpress post?
- WordPress post filter menu
- Not all posts showing in query
- WP_Query custom field pass the post id
- How to convert query sql to shortcode in wordpress?
- Use posts_where to exclude posts ids from wp_query
- Current and next month posts
- Why does WordPress search returns same number of results for every search query?
- Same post appears in related Posts?
- Sidebar limiting to 10 posts?
- Override WordPress core post-template.php block template
- How to show multiple posts thumbnail, title and date in widget
- WP_Query outputs wrong post in custom post type
- how to show comments only author which send own posts in wordpress
- Group first, 2nd, 3rd, etc posts by category terms
- Change Old WordPress Post Date Year
- Display/Filter post using if else statement
- How to sort WP_Post Object array by object field in php?
- Search results for ACF data
- Query prints posts without specific categories
- Numbered Pagination Showing The Same Posts After Altering WP_Query
- Order by meta_key field in WordPress not meta_value field value
- How to create page with post content in it?
- How to remove a post from results by ID after query?
- Show 5 posts and than 3 posts offset with pagination
- Override wp_link_pages pagebreak with filter
- Loop through all posts showing duplicates
- WP_Query extended with AJAX
- Manipulate query to show specific post
- WordPress text field in array problem
- Random order of the 5 most popular posts
- My custom query is displaying random posts in random order
- Get query result according to merged array
- Blog only showing one post even though more published
- WordPress loop uses unmodified posts array, why?
- Sort / Filter Queries
- How to show the posts list into a static page? Problems to use the loop into a static page
- How do I control the fallback query after the original query returned cero posts?
- Order posts by separate menu order for different sub-categories
- Adding a category at even positions on main loop with modified pagination
- Displaying Results From Custom Taxonomy Query
- Multiple loops on a Search result page?
- What is wrong with this wp_query?
- WP_Query: Fetch posts that are in (category1 and not in category2), OR posts that are not in cagegory1
- Exclude sub sub categories from displaying in the archive page
- How do I show the post title if an advanced custom field hasn’t been used?
- How add class the_content();?
- How do I get content of custom post type through post ID
- Filters do not work when there are multiple (one works)