Make WordPress Core

Opened 15 years ago

Closed 15 years ago

#12421 closed defect (bug) (fixed)

wp_list_bookmarks fails when orderby parameter is a comma separated list.

Reported by: vtxyzzy's profile vtxyzzy Owned by: sorich87's profile sorich87
Milestone: 3.0 Priority: normal
Severity: normal Version: 2.9.1
Component: Template Keywords: has-patch
Focuses: Cc:

Description

wp_list_bookmarks returns nothing when the orderby parameter is a comma separated list.

This works:

wp_list_bookmarks('categorize=0&category_name=Blogroll&orderby=rating'); 

This fails (no output):

wp_list_bookmarks('categorize=0&category_name=Blogroll&orderby=rating,name'); 

This works:

wp_list_bookmarks('categorize=0&category_name=Blogroll&orderby=rating,link_name'); 

The problem lies in this block of code from wp-includes/bookmark.php, line 231:

switch ($orderby) {
   case 'length':
      $length = ", CHAR_LENGTH(link_name) AS length";
      break;
   case 'rand':
      $orderby = 'rand()';
      break;
   default:
      $orderby = "link_" . $orderby;
}
}}

The prefix "link_" is added to the $orderby string, causing only the first name in the list to be correct.


Attachments (2)

wp_list_bookmarks_patch.patch (470 bytes) - added by sorich87 15 years ago.
wp_list_bookmarks_patch.2.patch (503 bytes) - added by scribu 15 years ago.
use trim()

Download all attachments as: .zip

Change History (8)

#1 @scribu
15 years ago

  • Milestone changed from Unassigned to Future Release
  • Type changed from defect (bug) to enhancement

Marking as enhancement, since the docs don't state that you can pass a comma separated list of values.

#2 @vtxyzzy
15 years ago

From the Codex:Template_Tags/wp_list_bookmarks

orderby
(string) Value to sort bookmarks on. This can be a COMMA separated list of values. Defaults to 'name' unless you pass the value of (empty), in which case it sets to 'id'. Valid options:

#3 @scribu
15 years ago

  • Component changed from General to Template
  • Keywords needs-patch added
  • Milestone changed from Future Release to 3.0
  • Type changed from enhancement to defect (bug)

My bad.

#4 @sorich87
15 years ago

  • Keywords has-patch added; needs-patch removed
  • Owner set to sorich87
  • Status changed from new to accepted

This is my first patch here. I was not sure how to name the temporary variables.

@scribu
15 years ago

use trim()

#5 @scribu
15 years ago

sorich87, welcome :)

You should initialise your variables, to avoid NOTICEs.

wp_list_bookmarks_patch.2.patch adds a trim() to avoid unexpected results.

#6 @nacin
15 years ago

  • Resolution set to fixed
  • Status changed from accepted to closed

(In [14131]) Allow orberby in wp_list_bookmarks to accept a comma-delimited list of fields, per docs. fixes #12421, props sorich87, scribu.

Note: See TracTickets for help on using tickets.