Opened 20 years ago
Closed 18 years ago
#247 closed defect (bug) (fixed)
Sort get_archive() output by more than just post_date
Reported by: | skippy | Owned by: | skippy |
---|---|---|---|
Milestone: | 2.1 | Priority: | normal |
Severity: | trivial | Version: | 1.6 |
Component: | Template | Keywords: | bg|squashed bg|commit |
Focuses: | Cc: |
Description
I have a need to sort the list of archives produced by wp_get_archives() and get_archives() alphabetically by post title, rather than chronologically by post_date. Adding two extra variables: "order" and "sort" to both functions would allow users to define additional sort and order terms. For example:
wp_get_archives("type=postbypost&sort=post_title&order=ASC")
Attachments (2)
Change History (15)
#3
@
19 years ago
here's another, possibly more elegant solution:
line 347 in wp-includes/template-functions-general.php:
} elseif (('postbypost' == $type) ('alpha' == $type)) { ('alpha' == $type) ? $orderby = "post_title ASC " : $orderby = "post_dat
e DESC ";
$arcresults = $wpdb->get_results("SELECT ID, post_date, post_title FROM
$wpdb->posts WHERE post_date < '$now' AND post_status = 'publish' ORDER BY " . $orderby . $limit);
#4
@
19 years ago
- Component changed from General to Template
- Milestone set to 1.6
- Version changed from 1.2 to 1.6
Here's a better patch for get_archives() and wp_get_archives() that introduces two new parameters:
orderby - defaults to post_date
sort - defaults to DESC
Existing templates should not break as these parameters are added to the end of get_archives().
#6
@
19 years ago
- Keywords bg|dev-feedback bg|2nd-opinion added
- Owner changed from anonymous to skippy
- Status changed from new to assigned
#7
@
19 years ago
See this cry for help in the forums: http://wordpress.org/support/topic/41183
Attempts to use examples in Codex on "alphabetizing posts" were foiled by this "bug" and only resolved by the work-round outlined by Skippy.
Here's an addition to get_archives() that adds support for "type=alpha" to produce an alphabetical list of archive links:
starts around line 363 in wp-includes/template-functions-general.php: