Reputation: 6354
I'm using the following code to query a custom post type. Despite being set to "post_status = publish" it is still showing blank "auto draft" pages on the front end, though I cannot locate them on backend. How do I get rid of these posts?
<?php
global $themeple_config;
$query = new WP_Query( array(
'post_type' => 'testimonial',
'post_status' => 'plublish',
'orderby' => 'post_date',
'order' => 'DESC'
) );
Upvotes: 1
Views: 1309
Reputation: 6354
It was simply a typo. "plublish
" should have been "publish
" obviously.
Correct code is as follows:
$query = new WP_Query( array(
'post_type' => 'testimonial',
'post_status' => 'publish',
'orderby' => 'post_date',
'order' => 'DESC'
) );
Credit to @yuyokk for noticing.
Upvotes: 1
Reputation: 606
see the following code if it can help you.
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 );
for more information click here
Upvotes: 0