php 如何移动所有的职位移动到垃圾桶

k5hmc34c  于 2023-01-08  发布在  PHP
关注(0)|答案(2)|浏览(109)

我面临的问题,在路线改变点击应用按钮,而选择移动到垃圾桶。

    • 注意**:移动到垃圾桶和应用程序是通过选择一些职位的工作。大量的,我试图移动到垃圾桶面临的问题。

网址:https://abcd.com/blog/probs/wp-admin/edit.php
选择移动到垃圾桶后,不选择任何帖子,并单击应用按钮url更改为
以防删除所有的职位,我得到了这样的路线
已更改的网址:https://abcd.com/probs//wp-admin/edit.php?paged=1

0ve6wy6x

0ve6wy6x1#

为此,您可以通过创建代码以编程方式进行尝试。
对于垃圾所有的职位,你试试这个代码:

function move_all_posts_to_trash() {
    $args = array(
        'post_type' => 'post', // Change this to the post type you want to move to trash
        'posts_per_page' => -1, // Get all posts
        'post_status' => 'publish' // Only get posts that are published
    );
    $posts = get_posts( $args );
    foreach ( $posts as $post ) {
        wp_trash_post( $post->ID ); // Move post to trash
    }
}
hgncfbus

hgncfbus2#

// If you want to move single post or page you can used by default wordpress function

Basic Example

Trash the default WordPress Post, “Hello World,” which has an ID of ‘1’.

<?php wp_trash_post( $post_id = 1 ); ?>

// For Multiple Posts using WP_Query using while loop.

You can used as per requirement like create shortcode or fire hooks.

function trash_custom_posts() { 

 $args = array (
    'post_type' => 'custom_post_type_slug',
    'post_status' => 'publish', 
    'posts_per_page' => -1
 );
 
 $query = new WP_Query( $args );
 
 while( $query->have_posts() ) {
 
    $query->the_post();
    
    $post_id = get_the_ID();

    wp_trash_post( $post_id );
 }
 
 wp_reset_postdata();
 
 }
 
 add_action( 'init', 'trash_custom_posts' );

相关问题