Hi all,
On my page, the Wayfinder’s sortBy feature is not working: the menu entries are always sorted by the page ID.
I was trying to sort pages within menus with the menuindex feature, but it would not work. Setting it manually or in the doc manager would not do it. I also tried sorting by the pagetitle (ie, &sortBy=`pagetitle`) and it also did not work.
It turns out that it’s an issue with the wayfinder’s sql query.
I think that everything’s OK with the snippet call, but here it is:
[[Wayfinder? &startId=`0` &level=`3` &sortBy=`menuindex` &parentClass=`hide` &parentRowTpl=`cssplay_parentRow` &outerTpl=`cssplay_outer` &innerTpl=`cssplay_inner` &rowTpl=`cssplay_row` &outerClass=`menu` &cssTpl=`cssplay_dropdown`]]
So I examined assets/snippets/wayfinder/wayfinder.inc.php. The sorting appears to be done on line 350, so I examined the SQL. Here it is, shortened for clarity (full SQL at the end):
SELECT DISTINCT sc.id, sc.pagetitle, sc.menuindex, sc.parent
FROM `modx`.`modx_site_content` sc
LEFT JOIN `modx`.`modx_document_groups` dg
ON dg.document = sc.id
WHERE sc.published=1 AND sc.deleted=0 AND (sc.privateweb=0) AND sc.hidemenu=0
GROUP BY sc.id
ORDER BY sc.menuindex ASC ;
I then went to the mysql console and manually issued that query. The results are not sorted by whatever you choose to put in the ORDER BY clause. The MySQL manual says (in
http://dev.mysql.com/doc/refman/5.0/en/select.html):
If you use GROUP BY, output rows are sorted according to the GROUP BY columns as if you had an ORDER BY for the same columns.
So I just eliminated the GROUP BY clause - I still have not found any use for it in this context. Now everything’s fine. Wayfinder puts the entries where they should be in the menu: according to the value of menuindex.
I do not think this is a wayfinder bug, as it would have been found earlier. But something must be wrong.
all the best,
joão
versions:
MODx 0.9.6.1B rev 3281
Wayfinder 2.0
mysql 5.0.51a-3 (Debian)
php 5.2.5-3
complete SQL query:
SELECT DISTINCT
sc.id, sc.menutitle, sc.pagetitle, sc.introtext, sc.menuindex, sc.published,
sc.hidemenu, sc.parent, sc.isfolder, sc.description, sc.alias, sc.longtitle, sc.type,
if(sc.type='reference',sc.content,'') as content, sc.template, sc.link_attributes
FROM `modx`.`modx_site_content` sc
LEFT JOIN `modx`.`modx_document_groups` dg
ON dg.document = sc.id
WHERE sc.published=1
AND sc.deleted=0
AND (sc.privateweb=0)
AND sc.hidemenu=0
AND sc.id IN (1,2,8,13,14,23,28,3,6,7,5,4,18,17,16,15,20,19,27,11,9,10,24,12,29,30,25,26,22,21)
GROUP BY sc.id
ORDER BY sc.menuindex ASC;