我正在使用下面页面中的代码,允许用户从前面删除他们的帖子。我有wp管理员完全封锁了网站用户。
我想做的是,当他们单击“删除”按钮时,帖子实际上进入草稿或挂起模式,因此仍然有帖子的记录,但前端无法查看它。
<!-- buyer-home.php -->
<?php
if( \'POST\' == $_SERVER[\'REQUEST_METHOD\'] ) {
set_query_var( \'postid1\', $_POST[\'postid\'] );
wp_delete_post( get_query_var( \'postid1\'), true ); }; ?>
<?php query_posts( array( \'author\' => $current_user->ID,\'post_status\' => \'publish\' , \'post_type\' => array( \'user_lists\' ) ) ); ?>
<?php if ( !have_posts() ): ?>
<div class="info" id="message">
<p>
<?php _e( \'No Lists found.\', \'lists\' ); ?>
</p>
</div>
<?php endif; ?>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<header class="entry-header">
<h1 class="entry-title center">Your Lists</h1>
</header>
<div class="entry-content">
<div class="table style1">
<div class="tr">
<div class="td style2">
<h2>Date And Time</h2>
</div>
<div class="td">
<h2>Delete</h2>
</div>
</div>
<?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>
<?php echo \'<div class="tr"><div class="td style2">\';
echo \'<a href="\'; the_permalink(); echo \'">\'; the_time(\'F j, Y\'); ?> at
<?php the_time(\'g:i a\'); echo \'</a>\';
echo \'</div><div class="td">\'; ?>
<?php change_post_status( the_ID, \'private\'); ?>
<form class="delete-list" action="" method="post">
<input type="hidden" name="postid" value="<?php the_ID(); ?>" />
<input class="more-button" type="submit" value="Delete" />
</form>
<?php echo \'</div></div>\'; ?>
<?php endwhile; ?>
<?php wp_reset_query(); ?>
<div class="tr">
<div class="td style2">
<h2>Date And Time</h2>
</div>
<div class="td">
<h2>Delete</h2>
</div>
</div>
</div>
</div><!-- .entry-content -->
</article><!-- #post -->
<!-- /buyer-home.php -->
最合适的回答,由SO网友:Johannes Pille 整理而成
只需更换
wp_delete_post( get_query_var( \'postid1\'), true );
与
wp_update_post( array( \'ID\' => get_query_var( \'postid1\' ), \'post_status\' => \'draft\' ) );
这是假设您的其余逻辑已经起作用了。