Adding Sort Order to taxonomy_select_nodes

I'm doing some display of nodes and I want to sort them as I display them, doing something like this:

$somenodes = taxonomy_select_nodes($terms, 'or', 2, FALSE, 'n.title');

This lets me sort by title which is handy in listings sometimes. For example, in the hacked up menu system that I've been using everywhere, this lets me display nodes by title.

In order to do this, 2 lines in taxonomy module need to be modified:

Line 824 From:

function taxonomy_select_nodes($tids = array(), $operator = 'or', $depth = 0, $pager = TRUE) {

To:

function taxonomy_select_nodes($tids = array(), $operator = 'or', $depth = 0, $pager = TRUE, $order = 'n.sticky DESC, n.created DESC') {

(this leaves the default sort order intact)

Secondly Line 839 From

$sql = 'SELECT DISTINCT(n.nid), n.sticky, n.title, n.created FROM {node} n INNER JOIN {term_node} tn ON n.nid = tn.nid WHERE tn.tid IN ('. $str_tids .') AND n.status = 1 ORDER BY n.sticky DESC, n.created DESC');

To

$sql = 'SELECT DISTINCT(n.nid), n.sticky, n.title, n.created FROM {node} n INNER JOIN {term_node} tn ON n.nid = tn.nid WHERE tn.tid IN ('. $str_tids .') AND n.status = 1 ORDER BY ' . $order;

Download modified taxonomy.module here

Post new comment

The content of this field is kept private and will not be shown publicly.
  • You can use Markdown syntax to format and style the text. Also see Markdown Extra for tables, footnotes, and more.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <blockquote> <pre>
  • Lines and paragraphs break automatically.

More information about formatting options