Search code examples
phpwordpressarchive

Wordpress - change archive query to include post_status='archive'


The Wordpress 'Post' archive only display posts set to 'publish'.

I have a custom post_status called 'archive' to use. The logic of the database query should include:

post_status='publish' OR post_status='archive'

I cannot work out how or where this should go to influence the 'wp_get_archives()' function so I ask for your help in being able to influence the query to display posts set to 'archive' status. Thank you.


Solution

  • According the source code in the Developer Resources, the WHERE expression is filtered using 'getarchives_where'. So you can add:

    function custom_status_getarchives_where($where) {
        return str_replace( 'post_status = \'publish\'',
            '(post_status = \'publish\' OR post_status = \'archive\')',
            $where
        );
    }
    
    add_filter( 'getarchives_where', 'custom_status_getarchives_where' );