Wordpress - 更改存档查询以包含 post_status='archive'

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

Wordpress 'Post' 存档仅显示设置为 'publish' 的帖子。

我有一个名为 'archive' 的自定义 post_status 可供使用。数据库查询的逻辑应该包括:

post_status='publish' OR post_status='archive'

我无法弄清楚这应该如何或在何处影响 'wp_get_archives()' 功能,因此我请求您帮助能够影响查询以显示设置为 'archive' 状态的帖子。谢谢。

根据 source code in the Developer Resources,使用 'getarchives_where' 过滤 WHERE 表达式。所以你可以添加:

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