正如@cybmeta提到的,信息存储在post meta表中。当我们丢弃一篇文章时,然后是文章元键_wp_trash_meta_status
与previous post status (发布,挂起,草稿,…)。
在wp_trash_post()
功能,我们有:
add_post_meta($post_id,\'_wp_trash_meta_status\', $post[\'post_status\']);
add_post_meta($post_id,\'_wp_trash_meta_time\', time());
因此,我们可以尝试:
// Get previous post status
$status = get_post_meta( $post_id, \'_wp_trash_meta_status\', true );
// Only untrash if the previous status wasn\'t a \'draft\'
if( \'draft\' !== $status )
wp_untrash_post( $post_id );
如果以前的帖子状态不是草稿,则只取消对帖子的刷新。
演示插件下面是一个示例,我们可以在trash 在后端的post列表表中查看:
然后,我们可以根据需要使用批量删除。
下面是一个支持它的演示插件:
<?php
/**
* Plugin Name: Demo Plugin
* Description: Adds the \'Previous Post Status\' Column in the \'trash\' post table view
* Plugin URI: http://wordpress.stackexchange.com/a/244261/26350
*/
namespace WPSE\\Q244254;
add_action( \'admin_head\', function()
{
// Only target the trash view on the edit.php page
if( \'trash\' !== get_query_var( \'post_status\' ) || ! did_action( \'load-edit.php\' ) )
return;
// Let\'s start it here
$o = new Main;
$o->init( $GLOBALS[\'wpdb\'] );
} );
class Main
{
private $db;
public function init( \\wpdb $db )
{
$this->db = $db;
add_filter( \'manage_post_posts_columns\', [ $this, \'columns\'] );
add_filter( \'manage_edit-post_sortable_columns\', [ $this, \'sortable_columns\' ] );
add_filter( \'posts_orderby\', [ $this, \'orderby\' ], 10, 2 );
add_action( \'manage_post_posts_custom_column\', [ $this, \'custom_column\' ], 10, 2 );
}
public function columns ( $columns )
{
// Place our new custom column right after the \'title\' column
$_columns = [];
foreach( (array) $columns as $key => $label )
{
$_columns[$key] = $label;
if( \'title\' === $key )
$_columns[\'wpse_prev_post_status\'] = esc_html__( \'Previous Post Status\', \'mydomain\' );
}
return $_columns;
}
public function custom_column( $column_name, $post_id )
{
// Display the previous post status
if ( $column_name == \'wpse_prev_post_status\' )
echo get_post_meta( $post_id, \'_wp_trash_meta_status\', true );
}
public function sortable_columns( $columns )
{
// Make our new column sortable
$columns[\'wpse_prev_post_status\'] = \'wpse_prev_post_status\';
return $columns;
}
public function orderby( $orderby, \\WP_Query $q )
{
// Implement the orderby support to our custom column
$_orderby = $q->get( \'orderby\' );
$_order = \'ASC\' === strtoupper( $q->get( \'order\' ) ) ? \'ASC\' : \'DESC\';
if(
is_admin()
&& $q->is_main_query()
&& \'wpse_prev_post_status\' === $_orderby
)
$orderby .= $this->db->prepare( "{$this->db->posts}.post_status %s", $_order );
return $orderby;
}
} // end class
注意,这里我们的目标是
post
岗位类型。
希望您可以根据需要进一步调整它,例如添加post status filtering.