【问题标题】:Stop Wordpress "Auto Drafts" from showing?停止显示 Wordpress“自动草稿”?
【发布时间】:2015-03-16 13:50:36
【问题描述】:

我正在使用以下代码来查询自定义帖子类型。尽管设置为“post_status = publish”,但它仍然在前端显示空白的“自动草稿”页面,尽管我无法在后端找到它们。如何删除这些帖子?

<?php
    global $themeple_config;

    $query = new WP_Query( array(
        'post_type'     => 'testimonial',
        'post_status'   => 'plublish',
        'orderby'       => 'post_date',
        'order'         => 'DESC'
    ) );

【问题讨论】:

  • 我认为只要您以管理员身份登录,您就会看到草稿帖子。
  • @yuyokk 无论是否登录,我都会在前端看到它们。
  • 如果它是您的真实代码,那么您的“发布”字词中有错字

标签: php wordpress


【解决方案1】:

这只是一个错字。 “plublish”显然应该是“publish”。

正确代码如下:

$query = new WP_Query( array(
    'post_type'     => 'testimonial',
    'post_status'   => 'publish',
    'orderby'       => 'post_date',
    'order'         => 'DESC'
) );

感谢@yuyokk 的注意。

【讨论】:

    【解决方案2】:

    如果对您有帮助,请参阅以下代码。

    global $wpdb;
    
    if ( ! $post = get_post( $post ) ) return;
    
    if ( 'publish' == $post->post_status ) return;
    
    $wpdb->update( $wpdb->posts, array( 'post_status' => 'publish' ), array( 'ID' => $post->ID ) );
    
    clean_post_cache( $post->ID );
    
    $old_status = $post->post_status;
    $post->post_status = 'publish';
    wp_transition_post_status( 'publish', $old_status, $post );
    

    更多信息请点击here

    【讨论】:

      猜你喜欢
      • 2017-04-21
      • 2013-06-10
      • 1970-01-01
      • 2014-05-07
      • 1970-01-01
      • 2017-12-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多