wp_query ignoring custom post_status

I have a custom post status called 'dead.' I am trying to create a wp_query to show all posts for a custom taxonomy. If I specify 'any' for the post_status I do get published posts and my 'dead' post_status posts. Likewise, if I set the post_status parameter to only 'dead' I do get just those posts. But, if I try to set the post_status to show both published and dead post_status posts via an array I can only get the published ones.

$args = array(
    'post_status' = array('publish', 'dead'),
    'post_type' = 'post',
    'posts_per_page' = -1,
    'orderby' = 'post_title',
    'order' = 'ASC',
    'tax_query' = array(
        array(
            'taxonomy' = 'linktypes',
            'field'    = 'id',
            'terms'    = '15'
        ),
    )
);  
$my_query = new wp_query( $args );

Does WordPress not allow you to specify both standard and custom post_statuses in an array like this? Or am I just doing something wrong?

UPDATE: As recommended, I am adding the code I use to create the custom post_status (as well as the code to add it to the admin screen and quick edit screen just in case that might be relevant.

function custom_post_status() {
    register_post_status( 'dead', array(
        'label'                     = _x( 'Dead', 'post' ),
        'public'                    = true,
        'exclude_from_search'       = false,
        'show_in_admin_all_list'    = true,
        'show_in_admin_status_list' = true,
        'label_count'               = _n_noop( 'Dead span class=count(%s)/span', 'Dead span class=count(%s)/span' ),
    ) );
}
add_action( 'init', 'custom_post_status' );


function my_post_submitbox_misc_actions() {
    global $post;
    //only when editing a post
    if( $post-post_type == 'post' ){
        // custom post status: dead
        $complete = '';
        $label = '';   

        if( $post-post_status == 'dead' ){
            $complete = ' selected=\selected\';
            $label = 'span id=\post-status-display\ Dead/span';
        }

        echo 'script
        jQuery(document).ready(function($){
            $(select#post_status).append(option value=\publish\ selected=\publish\Publish/option);
            $(select#post_status).append(option value=\dead\ '.$complete.'Dead/option);
            $(.misc-pub-section label).append('.$label.');
        });
        /script';
    }
}
add_action( 'post_submitbox_misc_actions', 'my_post_submitbox_misc_actions' );


function rudr_status_into_inline_edit() { 
    echo script
    jQuery(document).ready( function() {
        jQuery( 'select[name=\_status\]' ).append( 'option value=\dead\Dead/option' );
    });
    /script;
}
add_action('admin_footer-edit.php','rudr_status_into_inline_edit');

UPDATE #2: I added print_r($my_query-request); to see the WP_Query request SQL and this is what I see.

using 'post_status' = array('dead'):

SELECT [...] AND ((wp_posts.post_status = 'dead')) GROUP BY [...]

using 'post_status' = array('publish','dead'):

SELECT [...] AND ((wp_posts.post_status = 'publish')) GROUP BY [...]

using 'post_status' = array('any'):

SELECT [...] AND ((wp_posts.post_status  'trash' AND wp_posts.post_status  'auto-draft')) GROUP BY [...]

using 'post_status' = array('publish','future'):

SELECT [...]  AND ((wp_posts.post_status = 'publish' OR wp_posts.post_status = 'future')) GROUP BY [...]

Topic post-status wp-query Wordpress

Category Web


I had the same issue and the reason was that I was running the query before registering the post status. So the post status was not registered and thus ignored in WP_Query

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.