在函数中添加以下代码后,它就可以工作了。php
function preview_draft_posts($query) {
if ( is_admin() || get_query_var(\'suppress_filters\') )
return $query;
$query->set(\'post_status\', array(\'publish\', \'pending\', \'draft\'));
return $query;
}
if(isset($_GET[\'p\']) && isset($_GET[\'post_type\']) && ($_GET[\'post_type\'] == \'deals\' || $_GET[\'post_type\'] == \'events\')&& get_current_user_id() > 0){
global $wpdb;
$deal_posts = $wpdb->prefix . \'posts\';
$sql_claim ="SELECT ID FROM $deal_posts WHERE ID=\'".$_GET[\'p\']."\' AND post_author=".get_current_user_id();
$myrows = $wpdb->get_row( $sql_claim, ARRAY_A );
if(isset($myrows[\'ID\']) ){
add_filter(\'pre_get_posts\', \'preview_draft_posts\');
}
}