- Posts: 4
COMMUNITY FORUM
Display certain extra fields in search results
- Panos
- Topic Author
- Offline
- New Member
Less
More
11 years 11 months ago - 11 years 11 months ago #107031
by Panos
Display certain extra fields in search results was created by Panos
Hey guys!
I've been using K2 for quite some time now and on a new website I'm building there is a small problem which is displaying certain extra fields (not all) at the search results page of Joomla. Not being able to show them by default I decided to write my own code that does the trick.
What I did is to write some code that queries the database -using the result's id- and gets all the extra fields using json decoding to display them in a readable format. My problem there, is that each item has 100 extra fields and json takes ages to decode them all when I have let's say 20 items per page. So I was wondering if there is a way to speed up the results?
Below you can see a snippet of the code to see if you can help a little:
This brings the first 16 extra fields of the item and then I decode the extra_fields column using json which has all the extra fields and their values, so I can display them at the search results page. I think I need to optimize my SQL code, so if anyone has a clue please help. I'm sure some other guys will need to do that, so I guess it will be helpful for the community.
Thanks in advance!
I've been using K2 for quite some time now and on a new website I'm building there is a small problem which is displaying certain extra fields (not all) at the search results page of Joomla. Not being able to show them by default I decided to write my own code that does the trick.
What I did is to write some code that queries the database -using the result's id- and gets all the extra fields using json decoding to display them in a readable format. My problem there, is that each item has 100 extra fields and json takes ages to decode them all when I have let's say 20 items per page. So I was wondering if there is a way to speed up the results?
Below you can see a snippet of the code to see if you can help a little:
SELECT e.id AS extra_id, e.name, e.type, i.extra_fields, g.name AS group_name FROM jos_k2_extra_fields e, jos_k2_categories c, jos_k2_items i, jos_k2_extra_fields_groups g WHERE i.catid = c.id AND g.id = c.extraFieldsGroup AND g.id = e.group AND e.published=1 AND i.id = ".$result->id." ORDER BY e.ordering ASC LIMIT 0, 16
Thanks in advance!
Please Log in or Create an account to join the conversation.
- william white
- Offline
- Platinum Member
Less
More
- Posts: 3722
11 years 11 months ago #107032
by william white
Replied by william white on topic Re: Display certain extra fields in search results
if you are using 2.6.2, you should be able to override generic.php and refer to the extra fields from the item that is current by using the new syntax
$this->item->extraFields->EXTRAFIELDALIASHERE->value
to display them without running a query
$this->item->extraFields->EXTRAFIELDALIASHERE->value
to display them without running a query
Please Log in or Create an account to join the conversation.
- Panos
- Topic Author
- Offline
- New Member
Less
More
- Posts: 4
11 years 11 months ago #107033
by Panos
Replied by Panos on topic Re: Display certain extra fields in search results
I'm using K2 2.4.1 and from what I saw using $this->item in Joomla's search results file -default_results.php located at /components/com_search/views/search/tmpl/- page won't work at all, as the results are displayed using the string $result-> and the only thing that is passed there is extra_fields_search which can't be used.
Please Log in or Create an account to join the conversation.
- roberto
- Offline
- New Member
Less
More
- Posts: 1
11 years 11 months ago #107034
by roberto
Replied by roberto on topic Re: Display certain extra fields in search results
hi panos i have the same problem but i still havent found a solution. the query you post it looks like dont work at all the results it's 0
can you share a solution if you'll find? it's becoming a nightmare form me!
can you share a solution if you'll find? it's becoming a nightmare form me!
Please Log in or Create an account to join the conversation.
- kobiavr
- Offline
- New Member
Less
More
- Posts: 4
11 years 3 months ago #107035
by kobiavr
Replied by kobiavr on topic Re: Display certain extra fields in search results
i have the same problem and i don't find solution
Please Log in or Create an account to join the conversation.