By stevec4 on Wednesday, 26 August 2020
Replies 4
Likes 0
Views 708
Votes 0
Hi guys
Just wondering if you can point me in the right direction to modify this function. I use it to sort events by category and it works well. What I was hoping to do is add some code to the function to place one category first always.

The name of the category is Meeting and it has a category id number of 20.

Thanks for the help
Steve


// Sort events by category
function sortjeventsbycat($a,$b){
if ($a->getCategoryName() == $b->getCategoryName()){
if ($a->title() == $b->title()) {
return 0;
}
return ($a->title() < $b->title()) ? -1 : 1;
}
return $a->getCategoryName() < $b->getCategoryName() ? -1 : 1;
}
something like this before line 10


if ($a->getCategoryName() == "Meeting")
return -1;
if ($b->getCategoryName() == "Meeting")
return 1;

should do it (but I haven't tested it)
·
4 years ago
·
0 Likes
·
0 Votes
·
0 Comments
·
Thank you Geraint, I will give it a try.

Steve
·
4 years ago
·
0 Likes
·
0 Votes
·
0 Comments
·
Hey Steve,

Just checking how that worked out with you?

Many thanks
Tony
·
4 years ago
·
0 Likes
·
0 Votes
·
0 Comments
·
It worked perfectly Tony, thanks for checking.

Steve
·
4 years ago
·
0 Likes
·
0 Votes
·
0 Comments
·
View Full Post