Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 316
Adam Fletcher Avatar asked Mar 15 '26 05:03

Adam Fletcher


1 Answers

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' );
like image 114
Jim Avatar answered Mar 17 '26 19:03

Jim



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!