modx icon
9th
Mar 10

MODx – Wayfinder Incorrect Order (menu index)

Posted Tuesday 9th March 2010
I just came across a problem with the MODx Wayfinder snippet not printing my navigation menu in the correct order. Even when re-ordering the menu indexes it wouldn’t change.

After a little investigation its down to the SQL statement Wayfinder uses. If you’re using an older version of MySQL (like 5.0.51) the GROUP BY and ORDER BY function behave differently when used together. To get around this problem you either need to update your MySQL server (recommended by sometimes not practical) or to make a quick alteration to the SQL statement in the Wayfinder snippet.

To change the query in the Wayfinder snippet first open it at assets/snippets/wayfinder/wayfinder.inc.php. In Wayfinder 2.0 the query is around line 360. Search for:

1
2
$sql = "SELECT DISTINCT {$fields} FROM {$tblsc} sc LEFT JOIN {$tbldg} dg ON dg.document = sc.id WHERE sc.published=1 AND sc.deleted=0 AND 
({$access}){$menuWhere} AND sc.id IN (".implode(',',$ids).") GROUP BY sc.id ORDER BY {$sort} {$this->_config['sortOrder']} {$sqlLimit};";

In the altered query we simply remove the GROUP BY function (which should be fine in 90% of cases). The query now looks like this:

1
2
$sql = "SELECT DISTINCT {$fields} FROM {$tblsc} sc LEFT JOIN {$tbldg} dg ON dg.document = sc.id WHERE sc.published=1 AND sc.deleted=0 AND 
({$access}){$menuWhere} AND sc.id IN (".implode(',',$ids).") ORDER BY {$sort} {$this->_config['sortOrder']} {$sqlLimit};";

After that save an upload (if need be). In the majority of cases everything should work fine.

Bookmark or share this page:

SociBook del.icio.us Digg Facebook Google Yahoo Buzz StumbleUpon

Related posts:

  1. Determing Login State (MODx)
  2. MODx – Include Page Content Snippet
  3. Changing MODx Managers Document Tree View Nodes


MSN Contact: contact [at] danielgibbs.net



3 Comments

  1. Miro 16 March 2010 5:42 pm

    Thanks!
    Simple fix without update version of MySQL!

    Thanks again

    Miro from Calgary

  2. mr5rule 30 December 2010 2:25 pm

    thanks for solution…

  3. cisco 6 December 2011 12:15 am

    Thanks, very useful, even in 2011 !

TrackBack URL

Leave a comment