繁体   English   中英

阻止显示Wordpress“自动草稿”?

[英]Stop Wordpress “Auto Drafts” from showing?

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

<?php
    global $themeple_config;

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

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

正确的代码如下:

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

感谢@yuyokk的注意。

如果有帮助,请参见以下代码。

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 );

欲了解更多信息,请点击这里

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM