Created
November 23, 2012 13:06
-
-
Save de-raaf-media/4135538 to your computer and use it in GitHub Desktop.
wordpress function hook - wp_get_archives by category
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// join term_relationships and term_taxonomy | |
add_filter( 'getarchives_join', 'customarchives_join' ); | |
// add where condition for category | |
add_filter( 'getarchives_where', 'customarchives_where' ); | |
// add where condition for date | |
add_filter('getarchives_where','filter_until_year_archives'); | |
function customarchives_join($join_clause) { | |
global $wpdb; | |
return $join_clause." 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)"; | |
} | |
function customarchives_where($where_clause) { | |
global $wpdb; | |
$include = get_cat_ID('news'); // category id to include | |
return $where_clause." AND $wpdb->term_taxonomy.taxonomy = 'category' AND $wpdb->term_taxonomy.term_id IN ($include)"; | |
} | |
function filter_until_year_archives($where_clause) { | |
$year = '1998.01.01 00:00:00'; | |
return $where_clause." AND post_date > '".$year."'"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment