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

Filters the SQL WHERE clause for retrieving archives.


Description Description


Parameters Parameters

$sql_where

(string) Portion of SQL query containing the WHERE clause.

$parsed_args

(array) An array of default arguments.


Top ↑

Source Source

File: wp-includes/general-template.php

View on Trac


Top ↑

Changelog Changelog

Changelog
Version Description
2.2.0 Introduced.


Top ↑

User Contributed Notes User Contributed Notes

  1. Skip to note 1 content
    Contributed by Khoi Pro

    The example of modifying a current query and add your own category id to filter:

    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)";
    }
    

    Read http://wpsocket.com/wpref/function/wp_get_archives/ to see what it should be work together.

You must log in before being able to contribute a note or feedback.