Make WordPress Core

Ticket #21596: 21596.diff

File 21596.diff, 3.1 KB (added by wonderboymusic, 8 years ago)
  • src/wp-includes/general-template.php

     
    13941394                'format' => 'html', 'before' => '',
    13951395                'after' => '', 'show_post_count' => false,
    13961396                'echo' => 1, 'order' => 'DESC',
     1397                'post_type' => 'post'
    13971398        );
    13981399
    13991400        $r = wp_parse_args( $args, $defaults );
    14001401
     1402        $post_type_object = get_post_type_object( $r['post_type'] );
     1403        if ( ! is_post_type_viewable( $post_type_object ) ) {
     1404                return;
     1405        }
     1406
    14011407        if ( '' == $r['type'] ) {
    14021408                $r['type'] = 'monthly';
    14031409        }
     
    14391445         * @param string $sql_where Portion of SQL query containing the WHERE clause.
    14401446         * @param array  $r         An array of default arguments.
    14411447         */
    1442         $where = apply_filters( 'getarchives_where', "WHERE post_type = 'post' AND post_status = 'publish'", $r );
     1448        $sql_where = $wpdb->prepare( "WHERE post_type = %s AND post_status = 'publish'", $r['post_type'] );
     1449        $where = apply_filters( 'getarchives_where', $sql_where, $r );
    14431450
    14441451        /**
    14451452         * Filter the SQL JOIN clause for retrieving archives.
     
    14731480                        $after = $r['after'];
    14741481                        foreach ( (array) $results as $result ) {
    14751482                                $url = get_month_link( $result->year, $result->month );
     1483                                if ( 'post' !== $r['post_type'] ) {
     1484                                        $url = add_query_arg( 'post_type', $r['post_type'], $url );
     1485                                }
    14761486                                /* translators: 1: month name, 2: 4-digit year */
    14771487                                $text = sprintf( __( '%1$s %2$d' ), $wp_locale->get_month( $result->month ), $result->year );
    14781488                                if ( $r['show_post_count'] ) {
     
    14931503                        $after = $r['after'];
    14941504                        foreach ( (array) $results as $result) {
    14951505                                $url = get_year_link( $result->year );
     1506                                if ( 'post' !== $r['post_type'] ) {
     1507                                        $url = add_query_arg( 'post_type', $r['post_type'], $url );
     1508                                }
    14961509                                $text = sprintf( '%d', $result->year );
    14971510                                if ( $r['show_post_count'] ) {
    14981511                                        $r['after'] = ' (' . $result->posts . ')' . $after;
     
    15121525                        $after = $r['after'];
    15131526                        foreach ( (array) $results as $result ) {
    15141527                                $url  = get_day_link( $result->year, $result->month, $result->dayofmonth );
     1528                                if ( 'post' !== $r['post_type'] ) {
     1529                                        $url = add_query_arg( 'post_type', $r['post_type'], $url );
     1530                                }
    15151531                                $date = sprintf( '%1$d-%2$02d-%3$02d 00:00:00', $result->year, $result->month, $result->dayofmonth );
    15161532                                $text = mysql2date( $archive_day_date_format, $date );
    15171533                                if ( $r['show_post_count'] ) {
     
    15401556                                        $arc_week_start = date_i18n( $archive_week_start_date_format, $arc_week['start'] );
    15411557                                        $arc_week_end   = date_i18n( $archive_week_end_date_format, $arc_week['end'] );
    15421558                                        $url            = sprintf( '%1$s/%2$s%3$sm%4$s%5$s%6$sw%7$s%8$d', home_url(), '', '?', '=', $arc_year, '&', '=', $result->week );
     1559                                        if ( 'post' !== $r['post_type'] ) {
     1560                                                $url = add_query_arg( 'post_type', $r['post_type'], $url );
     1561                                        }
    15431562                                        $text           = $arc_week_start . $archive_week_separator . $arc_week_end;
    15441563                                        if ( $r['show_post_count'] ) {
    15451564                                                $r['after'] = ' (' . $result->posts . ')' . $after;