get_archives query filters from westi. fixes #3866

git-svn-id: http://svn.automattic.com/wordpress/trunk@5004 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2007-03-09 04:09:24 +00:00
parent f774780aff
commit f4ce503381
1 changed files with 9 additions and 5 deletions

View File

@ -350,8 +350,12 @@ function wp_get_archives($args = '') {
$add_hours = intval(get_option('gmt_offset'));
$add_minutes = intval(60 * (get_option('gmt_offset') - $add_hours));
//filters
$where = apply_filters('getarchives_where', "WHERE post_type = 'post' AND post_status = 'publish'", $r );
$join = apply_filters('getarchives_join', "", $r);
if ( 'monthly' == $type ) {
$arcresults = $wpdb->get_results("SELECT DISTINCT YEAR(post_date) AS `year`, MONTH(post_date) AS `month`, count(ID) as posts FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish' GROUP BY YEAR(post_date), MONTH(post_date) ORDER BY post_date DESC" . $limit);
$arcresults = $wpdb->get_results("SELECT DISTINCT YEAR(post_date) AS `year`, MONTH(post_date) AS `month`, count(ID) as posts FROM $wpdb->posts $join $where GROUP BY YEAR(post_date), MONTH(post_date) ORDER BY post_date DESC" . $limit);
if ( $arcresults ) {
$afterafter = $after;
foreach ( $arcresults as $arcresult ) {
@ -363,7 +367,7 @@ function wp_get_archives($args = '') {
}
}
} elseif ('yearly' == $type) {
$arcresults = $wpdb->get_results("SELECT DISTINCT YEAR(post_date) AS `year`, count(ID) as posts FROM $wpdb->posts WHERE post_type ='post' AND post_status = 'publish' GROUP BY YEAR(post_date) ORDER BY post_date DESC" . $limit);
$arcresults = $wpdb->get_results("SELECT DISTINCT YEAR(post_date) AS `year`, count(ID) as posts FROM $wpdb->posts $join $where GROUP BY YEAR(post_date) ORDER BY post_date DESC" . $limit);
if ($arcresults) {
$afterafter = $after;
foreach ($arcresults as $arcresult) {
@ -375,7 +379,7 @@ function wp_get_archives($args = '') {
}
}
} elseif ( 'daily' == $type ) {
$arcresults = $wpdb->get_results("SELECT DISTINCT YEAR(post_date) AS `year`, MONTH(post_date) AS `month`, DAYOFMONTH(post_date) AS `dayofmonth`, count(ID) as posts FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish' GROUP BY YEAR(post_date), MONTH(post_date), DAYOFMONTH(post_date) ORDER BY post_date DESC" . $limit);
$arcresults = $wpdb->get_results("SELECT DISTINCT YEAR(post_date) AS `year`, MONTH(post_date) AS `month`, DAYOFMONTH(post_date) AS `dayofmonth`, count(ID) as posts FROM $wpdb->posts $join $where GROUP BY YEAR(post_date), MONTH(post_date), DAYOFMONTH(post_date) ORDER BY post_date DESC" . $limit);
if ( $arcresults ) {
$afterafter = $after;
foreach ( $arcresults as $arcresult ) {
@ -389,7 +393,7 @@ function wp_get_archives($args = '') {
}
} elseif ( 'weekly' == $type ) {
$start_of_week = get_option('start_of_week');
$arcresults = $wpdb->get_results("SELECT DISTINCT WEEK(post_date, $start_of_week) AS `week`, YEAR(post_date) AS yr, DATE_FORMAT(post_date, '%Y-%m-%d') AS yyyymmdd, count(ID) as posts FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish' GROUP BY WEEK(post_date, $start_of_week), YEAR(post_date) ORDER BY post_date DESC" . $limit);
$arcresults = $wpdb->get_results("SELECT DISTINCT WEEK(post_date, $start_of_week) AS `week`, YEAR(post_date) AS yr, DATE_FORMAT(post_date, '%Y-%m-%d') AS yyyymmdd, count(ID) as posts FROM $wpdb->posts $join $where GROUP BY WEEK(post_date, $start_of_week), YEAR(post_date) ORDER BY post_date DESC" . $limit);
$arc_w_last = '';
$afterafter = $after;
if ( $arcresults ) {
@ -410,7 +414,7 @@ function wp_get_archives($args = '') {
}
} elseif ( ( 'postbypost' == $type ) || ('alpha' == $type) ) {
('alpha' == $type) ? $orderby = "post_title ASC " : $orderby = "post_date DESC ";
$arcresults = $wpdb->get_results("SELECT * FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish' ORDER BY $orderby $limit");
$arcresults = $wpdb->get_results("SELECT * FROM $wpdb->posts $join $where $orderby $limit");
if ( $arcresults ) {
foreach ( $arcresults as $arcresult ) {
if ( $arcresult->post_date != '0000-00-00 00:00:00' ) {