This is quite hard to explain, so please bear with me.
I am trying to put a list of 'related' items on the item page (title, link, thumbnail). The relation is set in an element I have added.
So, say I am viewing an item with the element 'relation' to to 'response'. I would like to show links to all other items that also have the same value in that element.
I have messed around with
get_records, but I couldn't work out how to filter the list by element, and I didn't seem to be able to get the required details (title, link, thumbnail) from the item object that is returned.
This might get close. The SearchByMetadata plugin does something very similar, but instead of listing the results on the item's page, it produces one link to the items browse page, with the search filter. If that's sufficient, that'd be a quick solution.
By analogy to what that plugin does, the array to pass in for the params in
get_records in the plugin looks like this:
'advanced' => array(
'element_id' => $elementId,
'type' => 'is exactly',
The tricky part will be digging up the variables.
$elementId is the id of the Element object. In the plugin, I get it from the $elementText object with $elementText->element_id. I'm not sure what the best way to dig that up with be in your case.
terms key is for the actual text value ('response', in your example).
Note that this will return all the items with that value, regardless of the 'original' item. If you need something more particular to the originating item, the Item Relations plugin might be a better starting point.
This is very helpful, thank you.
I used the snippet you posted in
get_records, having found the id of the element like this:
$relatedElement = get_db()->getTable('Element')->findByElementSetNameAndElementName('Element Set', 'Related Item Tag');
$relatedId = $relatedElement->id;
It's returning the whole item object, but I am having a little trouble picking it apart to get the data I need. It doesn't appear to directly contain the even the Title.
Is there a guide for this, or can you give me some pointers? I am specifically looking for the item Title, URL and Thumbnail.
metadata function will get you the title and other data.
files_for_item is a good bet for the thumbnail.
link_to_item sounds like what you are looking for for the url. If not, there are some other global functions that we can try looking at.