The Techjoomla Blog

Stay updated with all the latest happenings at Techjoomla. From news about the developments in your favourite extensions to Tips & Tricks about the Joomla CMS, Framework & Development.
Font size: +
1 minute reading time (220 words)

Searching zoo items with field values

Searching zoo items with field values

Note: This Blog is targeted to developers!

As Joomla developers, you might have come across an issue wherein you need zoo items which have specific value under specific field?

Let's say you have a site where there are some discount offers on some books under different categories. For such books to show up under offers module, you need to have one zoo field saying ‘Have offer?’ with value ‘yes’. Also, you might be aware that the way zoo stores its field values is very tricky and it will be a huge task to get such items using database query.

Zoo provides the api for it, named ‘SearchElements’.

So we need zoo items list having field as ‘Have offer?’ and value ‘yes’, then this api is for you.

Here is how it is done!

// Create the zoo instance
$app			= App::getInstance('zoo');

//Take an element id of the field you want to search for and its value. Create array of it as api requires associative array format for it.
$element_id  = array('7b53d24f-6e22-4b8b-bfd9-b33ecda4aa8a'=>'y');

// Here is the zoo api that you need to add. First parameter is element array and second is application id.
$itemlist = $app->table->item->searchElements($element_id, '1');

 

And $itemlist will provide you all searched items.

I hope now you will be able to search zoo items with field values :)

1
×
Stay Informed

When you subscribe to the blog, we will send you an e-mail when there are new updates on the site so you wouldn't miss them.

The Joomla Speak! In Conversation with Sander Potj...
Shika Beta 16 with New features for Lesson & Quiz ...

Related Posts

 

Blog Topics