Make WordPress Core

Opened 6 years ago

Closed 6 years ago

#12421 closed defect (bug) (fixed)

wp_list_bookmarks fails when orderby parameter is a comma separated list.

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


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

This works:


This fails (no output):


This works:


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";
   case 'rand':
      $orderby = 'rand()';
      $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 6 years ago.
wp_list_bookmarks_patch.2.patch (503 bytes) - added by scribu 6 years ago.
use trim()

Download all attachments as: .zip

Change History (8)

#1 @scribu
6 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
6 years ago

From the Codex:Template_Tags/wp_list_bookmarks

(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
6 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
6 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.

6 years ago

use trim()

#5 @scribu
6 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
6 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.