Keyword

Sorting K2 items by extra fields

More
12 years 5 months ago - 12 years 5 months ago #64986 by Kr0nZ
Sorting K2 items by extra fields was created by Kr0nZ
Hi,
ive been searching high and low for a way to sort articles by specific extra fields. (the user/visitor should be able to choose how they want it sorted)

To me this seems like something that would be a common need for people who want to use extra fields

i tried searching google but that just leads me to this site, but all the links are broken (bad request).

Please Log in or Create an account to join the conversation.

More
12 years 5 months ago #64987 by Kr0nZ
Replied by Kr0nZ on topic Re: Sorting K2 items by extra fields
so is their really no way to do this?

seems pretty strange for something so common

so the only use for extra fields is displaying it to the user?

Please Log in or Create an account to join the conversation.

More
11 years 8 months ago #64988 by Gianluca
Replied by Gianluca on topic Re: Sorting K2 items by extra fields
hello, did you get a solution? I have an extra field for articles that is a date.. and i need to sort them with it...

Please Log in or Create an account to join the conversation.

More
11 years 7 months ago #64989 by Ralf Longwitz
Replied by Ralf Longwitz on topic Re: Sorting K2 items by extra fields
Me too, I'd love to be able to do that.

Please Log in or Create an account to join the conversation.

More
11 years 6 months ago #64990 by jeyjoo
Replied by jeyjoo on topic Re: Sorting K2 items by extra fields
Hi guys, if you are still looking for a solution, we worked it out. The solution is an override of the template, but just one line is added.
We have an events section here www.vidalatinaweb.com/it/eventi/congressi-ed-eventi , that has an extra field "date". we wanted to order by this field (this would work with any other extra field you want to order by).

Solution
Create a menu item linking to an empty article.
Create a module k2 contents that selects from your k2 category, that appears on your new empty page
For "Order by", select "Title alphabetical" - we use this as we are going to hack it - so it needs to be an order you will not use for any other module
Open the file modules/mod_k2_content/helper.php
on line 195 find the code

case 'alpha' :
$orderby = 'i.title DESC';
break;

and replace with:

case 'alpha' :
$orderby = 'i.extra_fields DESC';
break;


This will work if you only have one extra field. If you have more than one extra field, you will have to modify the solution, but I think you get the general idea.

Please Log in or Create an account to join the conversation.

More
11 years 6 months ago #64991 by Ralf Longwitz
Replied by Ralf Longwitz on topic Re: Sorting K2 items by extra fields
Thanks a lot jayjoo. I did not want to use a module for this. Therefore I used your instructions to change a component file:
\components\com_k2\models\itemlist.php

(I don't know how to do a proper override of this file.)

There I added my order instruction in line 334, overwriting the default ordering (by id):
$orderby = 'i.alias ASC';

Please Log in or Create an account to join the conversation.

More
9 years 11 months ago #64992 by Remik
Replied by Remik on topic Re: Sorting K2 items by extra fields
Hello.
I'm wondering if there is any way or possibility to show the program to treat this extra field content as numerical value? It would solve all problems with sorting articles by the price. At the moment this solution, which uses alphabetical type of sorting, works only in terms of where the price range is in the same range. For instance, if we have 2 articles with one extra field, which is the price, where one of them is 289,00 and the second is 1 000,00, it will simply list the second article as first.
Thanks in advance.

Please Log in or Create an account to join the conversation.

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
9 years 11 months ago #64993 by Krikor Boghossian
Replied by Krikor Boghossian on topic Re: Sorting K2 items by extra fields
This should be done through a K2 Plugin to make it bulletproof.

JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)

Please Log in or Create an account to join the conversation.

More
9 years 11 months ago #64994 by Remik
Replied by Remik on topic Re: Sorting K2 items by extra fields
Ofcourse it should, but as a temporary solution this might work as well.

Please Log in or Create an account to join the conversation.

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
9 years 11 months ago #64995 by Krikor Boghossian
Replied by Krikor Boghossian on topic Re: Sorting K2 items by extra fields
I have to say, it might be better to start with the plugin instead of migrating data in the long run. If you don't really have that many items then you can disregard this :)

JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)

Please Log in or Create an account to join the conversation.


Powered by Kunena Forum