Warning: Trying to access array offset on false in /www/wwwroot/www.wpdongli.com/wp-content/themes/WPdongli/functions/wp.php on line 216
getarchives_where - 过滤用于检索存档的SQL WHERE子句 - WordPress钩子 - WordPress动力
当前浏览:首页 / WordPress钩子 / getarchives_where

apply_filters( 'getarchives_where', string $sql_where, array $parsed_args )

过滤用于检索存档的SQL WHERE子句


Warning: Undefined array key -1 in /www/wwwroot/www.wpdongli.com/wp-content/themes/WPdongli/functions/reference-cat.php on line 185

Warning: Undefined array key 2 in /www/wwwroot/www.wpdongli.com/wp-content/themes/WPdongli/functions/reference-cat.php on line 186

Warning: Undefined variable $searchand in /www/wwwroot/www.wpdongli.com/wp-content/themes/WPdongli/functions/wp.php on line 154

Warning: Undefined array key "7ef758c0aeb7c8f0647bf6d94174ed5f" in /www/wwwroot/www.wpdongli.com/wp-content/themes/WPdongli/functions/wp.php on line 223

Warning: Undefined variable $searchand in /www/wwwroot/www.wpdongli.com/wp-content/themes/WPdongli/functions/wp.php on line 154

Warning: Undefined array key "05f0a0b6ab38a82521ca34df75374810" in /www/wwwroot/www.wpdongli.com/wp-content/themes/WPdongli/functions/wp.php on line 223

getarchives


参数

$sql_wherestring
包含WHERE子句的SQL查询部分。
$parsed_argsarray
默认参数的数组。


源码

查看源码 官方文档


更新日志

版本描述
2.2.0开始引入

使用示例

  • 示例1

    修改当前查询并将自己的类别id添加到筛选器的示例:

    add_filter( 'getarchives_where', 'custom_archive_by_category_where' );
    add_filter( 'getarchives_join', 'custom_archive_by_category_join' ); // You must add `join` to keep it works. Adding only `where` will return nothing
    
    function custom_archive_by_category_where($x) {
        global $wpdb;
        $current_term_slug = get_query_var( 'news_category' );
     
        if (!empty($current_term_slug)) {
            $current_term = get_term_by('slug', $current_term_slug, 'news_category');
     
            if (is_wp_error($current_term) ) {
                return $x;
            }
     
            $current_term_id = $current_term->term_id;
     
            return $x . " AND $wpdb->term_taxonomy.taxonomy = 'news_category' AND $wpdb->term_taxonomy.term_id IN ($current_term_id)";
     
        }
     
        return $x;
    }
    
    function custom_archive_by_category_join( $x ) {
        global $wpdb;
        return $x . " INNER JOIN $wpdb->term_relationships ON ($wpdb->posts.ID = $wpdb->term_relationships.object_id) INNER JOIN $wpdb->term_taxonomy ON ($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id)";
    }

    查阅 wp_get_archives(),看看什么是它应该一起工作的。