【问题标题】:Wordpress - change archive query to include post_status='archive'Wordpress - 更改存档查询以包含 post_status='archive'
【发布时间】:2016-11-15 11:56:04
【问题描述】:

Wordpress“发布”存档仅显示设置为“发布”的帖子。

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

post_status='publish' OR post_status='archive'

我无法确定这应该如何或在何处影响“wp_get_archives()”函数,因此我请求您帮助影响查询以显示设置为“存档”状态的帖子。谢谢。

【问题讨论】:

标签: php wordpress archive


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-25
    • 1970-01-01
    相关资源
    最近更新 更多