WordPress.org

Make WordPress Core

Opened 6 years ago

Closed 5 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:

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 5 years ago.
wp_list_bookmarks_patch.2.patch (503 bytes) - added by scribu 5 years ago.
use trim()

Download all attachments as: .zip

Change History (8)

comment:1 @scribu6 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.

comment:2 @vtxyzzy6 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:

comment:3 @scribu6 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.

comment:4 @sorich875 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.

@scribu5 years ago

use trim()

comment:5 @scribu5 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.

comment:6 @nacin5 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.