Changeset 34686
- Timestamp:
- 09/29/2015 05:10:10 AM (9 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/general-template.php
r34474 r34686 1358 1358 * 1359 1359 * @since 1.2.0 1360 * @since 4.4.0 $post_type arg was added. 1360 1361 * 1361 1362 * @see get_archives_link() … … 1384 1385 * @type string $order Whether to use ascending or descending order. Accepts 'ASC', or 'DESC'. 1385 1386 * Default 'DESC'. 1387 * @type string $post_type Post type. Default 'post'. 1386 1388 * } 1387 1389 * @return string|void String when retrieving. … … 1395 1397 'after' => '', 'show_post_count' => false, 1396 1398 'echo' => 1, 'order' => 'DESC', 1399 'post_type' => 'post' 1397 1400 ); 1398 1401 1399 1402 $r = wp_parse_args( $args, $defaults ); 1403 1404 $post_type_object = get_post_type_object( $r['post_type'] ); 1405 if ( ! is_post_type_viewable( $post_type_object ) ) { 1406 return; 1407 } 1408 $r['post_type'] = $post_type_object->name; 1400 1409 1401 1410 if ( '' == $r['type'] ) { … … 1440 1449 * @param array $r An array of default arguments. 1441 1450 */ 1442 $where = apply_filters( 'getarchives_where', "WHERE post_type = 'post' AND post_status = 'publish'", $r ); 1451 $sql_where = $wpdb->prepare( "WHERE post_type = %s AND post_status = 'publish'", $r['post_type'] ); 1452 $where = apply_filters( 'getarchives_where', $sql_where, $r ); 1443 1453 1444 1454 /** … … 1474 1484 foreach ( (array) $results as $result ) { 1475 1485 $url = get_month_link( $result->year, $result->month ); 1486 if ( 'post' !== $r['post_type'] ) { 1487 $url = add_query_arg( 'post_type', $r['post_type'], $url ); 1488 } 1476 1489 /* translators: 1: month name, 2: 4-digit year */ 1477 1490 $text = sprintf( __( '%1$s %2$d' ), $wp_locale->get_month( $result->month ), $result->year ); … … 1494 1507 foreach ( (array) $results as $result) { 1495 1508 $url = get_year_link( $result->year ); 1509 if ( 'post' !== $r['post_type'] ) { 1510 $url = add_query_arg( 'post_type', $r['post_type'], $url ); 1511 } 1496 1512 $text = sprintf( '%d', $result->year ); 1497 1513 if ( $r['show_post_count'] ) { … … 1513 1529 foreach ( (array) $results as $result ) { 1514 1530 $url = get_day_link( $result->year, $result->month, $result->dayofmonth ); 1531 if ( 'post' !== $r['post_type'] ) { 1532 $url = add_query_arg( 'post_type', $r['post_type'], $url ); 1533 } 1515 1534 $date = sprintf( '%1$d-%2$02d-%3$02d 00:00:00', $result->year, $result->month, $result->dayofmonth ); 1516 1535 $text = mysql2date( $archive_day_date_format, $date ); … … 1541 1560 $arc_week_end = date_i18n( $archive_week_end_date_format, $arc_week['end'] ); 1542 1561 $url = sprintf( '%1$s/%2$s%3$sm%4$s%5$s%6$sw%7$s%8$d', home_url(), '', '?', '=', $arc_year, '&', '=', $result->week ); 1562 if ( 'post' !== $r['post_type'] ) { 1563 $url = add_query_arg( 'post_type', $r['post_type'], $url ); 1564 } 1543 1565 $text = $arc_week_start . $archive_week_separator . $arc_week_end; 1544 1566 if ( $r['show_post_count'] ) { -
trunk/tests/phpunit/tests/functions/getArchives.php
r28960 r34686 89 89 $this->assertEquals( $expected['order_desc'], trim( wp_get_archives( array( 'echo' => false, 'order' => 'DESC' ) ) ) ); 90 90 } 91 92 /** 93 * @ticket 21596 94 */ 95 function test_wp_get_archives_post_type() { 96 register_post_type( 'taco', array( 'public' => true ) ); 97 98 $this->factory->post->create( array( 99 'post_type' => 'taco', 100 'post_author' => '1', 101 'post_date' => '2014-10-23 19:34:42' 102 ) ); 103 104 $oct_url = esc_url( add_query_arg( 'post_type', 'taco', get_month_link( 2014, 10 ) ) ); 105 $expected = "<li><a href='{$oct_url}'>October 2014</a></li>"; 106 $archives = wp_get_archives( array( 'echo' => false, 'post_type' => 'taco' ) ); 107 $this->assertEquals( $expected, trim( $archives ) ); 108 } 91 109 }
Note: See TracChangeset
for help on using the changeset viewer.