Keyword

How to limit related items to a category?

  • Gorast
  • Gorast's Avatar Topic Author
  • Offline
  • Premium Member
More
6 years 6 months ago #169938 by Gorast
Hi,
I need to relate Actor to its Performance. I do this by tags. The problem is that other actors that have same performance show in the related items. How can I limit related items to show related items ONLY from category Performances?

Thanks,
Gorast

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

More
6 years 6 months ago #169942 by JoomlaWorks
Replied by JoomlaWorks on topic How to limit related items to a category?
The query does not distinguish categories. We could have it though as an option in upcoming releases (noted).

In the meantime, your best bet is to simply override the itemlist.php model in the frontend (function getRelatedItems()) and simply extend with your rules.

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

  • Gorast
  • Gorast's Avatar Topic Author
  • Offline
  • Premium Member
More
6 years 6 months ago #169943 by Gorast
Replied by Gorast on topic How to limit related items to a category?
I tried to modify the file ofc :D but always end up with error.
Never learned how really Joomla draw the id for the categories.

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

More
6 years 6 months ago #169944 by JoomlaWorks
Replied by JoomlaWorks on topic How to limit related items to a category?
It's not Joomla in this case, it's a function specific to K2 and it's plain SQL. Nothing fancy.

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

  • Gorast
  • Gorast's Avatar Topic Author
  • Offline
  • Premium Member
More
6 years 6 months ago #169945 by Gorast
Replied by Gorast on topic How to limit related items to a category?
:D
Easy for you to say. I'll try to find my way around or I'll wait for the upcoming release :D
Thanks.

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

  • Mohamed Abdelaziz
  • Mohamed Abdelaziz's Avatar
  • Offline
  • Platinum Member
  • Joomla Developer
More
6 years 6 months ago #169961 by Mohamed Abdelaziz
Replied by Mohamed Abdelaziz on topic How to limit related items to a category?
Try to replace the query line with this one:
$query = "SELECT t.itemID FROM #__k2_tags_xref AS t JOIN #__k2_items AS i ON t.itemID = i.id WHERE t.tagID IN ({$sql}) AND t.itemID != {$itemID}  AND i.catid = (SELECT catid FROM #__k2_items WHERE id = {$itemID}) GROUP BY t.itemID";

If it works with you, I can help to implement this feature in the upcoming release.

Multiple Extra Fields Groups for K2
AutoMeta for K2
Chained Fields for K2
More K2 Extensions In My Extensions Store

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

  • Gorast
  • Gorast's Avatar Topic Author
  • Offline
  • Premium Member
More
6 years 6 months ago #169969 by Gorast
Replied by Gorast on topic How to limit related items to a category?
Should I run this in phpMyAdmin?

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

  • Mohamed Abdelaziz
  • Mohamed Abdelaziz's Avatar
  • Offline
  • Platinum Member
  • Joomla Developer
More
6 years 6 months ago #169971 by Mohamed Abdelaziz
Replied by Mohamed Abdelaziz on topic How to limit related items to a category?

Gorast wrote: Should I run this in phpMyAdmin?


No, you will modify itemlist.php model in the frontend as Fotis said

You will replace this line:
$query = "SELECT itemID FROM #__k2_tags_xref WHERE tagID IN ({$sql}) AND itemID!={$itemID} GROUP BY itemID";

Multiple Extra Fields Groups for K2
AutoMeta for K2
Chained Fields for K2
More K2 Extensions In My Extensions Store

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

  • Gorast
  • Gorast's Avatar Topic Author
  • Offline
  • Premium Member
More
6 years 6 months ago - 6 years 6 months ago #170159 by Gorast
Replied by Gorast on topic How to limit related items to a category?
It did nothing. Should I manually put the ID of the Category I want the items from?

Tnx,
Gorast
Last edit: 6 years 6 months ago by Gorast.

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

  • Mohamed Abdelaziz
  • Mohamed Abdelaziz's Avatar
  • Offline
  • Platinum Member
  • Joomla Developer
More
6 years 6 months ago #170162 by Mohamed Abdelaziz
Replied by Mohamed Abdelaziz on topic How to limit related items to a category?
Have you modified the models/itemlist.php file?
The query I detects the category id from the item being viewed.

Multiple Extra Fields Groups for K2
AutoMeta for K2
Chained Fields for K2
More K2 Extensions In My Extensions Store

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

  • Gorast
  • Gorast's Avatar Topic Author
  • Offline
  • Premium Member
More
6 years 6 months ago #170165 by Gorast
Replied by Gorast on topic How to limit related items to a category?
Hey,
yes, I did modified that file. The thing is that I dont want items from same category, I want from items from specific category id number 61.

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

  • Mohamed Abdelaziz
  • Mohamed Abdelaziz's Avatar
  • Offline
  • Platinum Member
  • Joomla Developer
More
6 years 6 months ago #170169 by Mohamed Abdelaziz
Replied by Mohamed Abdelaziz on topic How to limit related items to a category?
In this case, you need to add the category id manually.

Multiple Extra Fields Groups for K2
AutoMeta for K2
Chained Fields for K2
More K2 Extensions In My Extensions Store

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

  • Gorast
  • Gorast's Avatar Topic Author
  • Offline
  • Premium Member
More
6 years 6 months ago #170172 by Gorast
Replied by Gorast on topic How to limit related items to a category?
$query = "SELECT t.itemID FROM #__k2_tags_xref AS t JOIN #__k2_items AS i ON t.itemID = i.id WHERE t.tagID IN ({$sql}) AND t.itemID != {$itemID} AND i.catid = (SELECT catid FROM #__k2_items WHERE id = {61}) GROUP BY t.itemID";

Is that it?

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

  • Mohamed Abdelaziz
  • Mohamed Abdelaziz's Avatar
  • Offline
  • Platinum Member
  • Joomla Developer
More
6 years 6 months ago #170173 by Mohamed Abdelaziz
Replied by Mohamed Abdelaziz on topic How to limit related items to a category?
It should be like this:
$query = "SELECT t.itemID FROM #__k2_tags_xref AS t JOIN #__k2_items AS i ON t.itemID = i.id WHERE t.tagID IN ({$sql}) AND t.itemID != {$itemID}  AND i.catid = 61 GROUP BY t.itemID";

Multiple Extra Fields Groups for K2
AutoMeta for K2
Chained Fields for K2
More K2 Extensions In My Extensions Store

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

  • Gorast
  • Gorast's Avatar Topic Author
  • Offline
  • Premium Member
More
6 years 6 months ago - 6 years 6 months ago #170174 by Gorast
Replied by Gorast on topic How to limit related items to a category?
OMG it works :D
Its not working for Parent category but if I specific the exact category it works!

Can I add another AND so another category is affected?
Like this
$query = "SELECT t.itemID FROM #__k2_tags_xref AS t JOIN #__k2_items AS i ON t.itemID = i.id WHERE t.tagID IN ({$sql}) AND t.itemID != {$itemID}  AND i.catid = 61 GROUP BY t.itemID AND i.catid = 62 GROUP BY t.itemID";

Thanks!

EDIT: Nope, its not working :D
Last edit: 6 years 6 months ago by Gorast.

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

  • Mohamed Abdelaziz
  • Mohamed Abdelaziz's Avatar
  • Offline
  • Platinum Member
  • Joomla Developer
More
6 years 6 months ago #170175 by Mohamed Abdelaziz
Replied by Mohamed Abdelaziz on topic How to limit related items to a category?
To add multiple categories, use this version:
$query = "SELECT t.itemID FROM #__k2_tags_xref AS t JOIN #__k2_items AS i ON t.itemID = i.id WHERE t.tagID IN ({$sql}) AND t.itemID != {$itemID}  AND i.catid IN (61,62) GROUP BY t.itemID";

Multiple Extra Fields Groups for K2
AutoMeta for K2
Chained Fields for K2
More K2 Extensions In My Extensions Store

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

  • Gorast
  • Gorast's Avatar Topic Author
  • Offline
  • Premium Member
More
6 years 6 months ago #170176 by Gorast
Replied by Gorast on topic How to limit related items to a category?
Damn it! Imba! How can I buy you a beer?! :D
Thanks!

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

  • Mohamed Abdelaziz
  • Mohamed Abdelaziz's Avatar
  • Offline
  • Platinum Member
  • Joomla Developer
More
6 years 6 months ago #170177 by Mohamed Abdelaziz
Replied by Mohamed Abdelaziz on topic How to limit related items to a category?

Gorast wrote: Damn it! Imba! How can I buy you a beer?! :D
Thanks!


You are welcome :)
If you want to buy me a beer, send me a message with how much you want to pay here: www.joomreem.com/contact-us

Thanks!

Multiple Extra Fields Groups for K2
AutoMeta for K2
Chained Fields for K2
More K2 Extensions In My Extensions Store

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

  • Gorast
  • Gorast's Avatar Topic Author
  • Offline
  • Premium Member
More
6 years 6 months ago #170178 by Gorast
Replied by Gorast on topic How to limit related items to a category?
Done :D

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


Powered by Kunena Forum