Skip to content

Instantly share code, notes, and snippets.

@drmmr763
Created December 4, 2012 14:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save drmmr763/4204676 to your computer and use it in GitHub Desktop.
Save drmmr763/4204676 to your computer and use it in GitHub Desktop.
Getting extra fields
<?php
/* I used to be able to get the extra fields of
** a k2 item by doing this:
*/
$id = $item->getId();
$db = JFactory::getDBO();
$query = "SELECT extra_fields FROM #__k2_items WHERE id={$id}";
$db->setQuery($query);
$row = $db->loadObject();
// Pre K2 2.6.2
$extrafields = K2ModelItem::getItemExtraFields($row);
/* After installing 2.5.2 update I the K2 data model for extra fields was updated.
** it now asks for a second parameter, the item object.
// function getItemExtraFields($itemExtraFields, &$item = null) item.php k2 model
*/
// What do I have to do to get this working again? I tried this:
$extrafields = K2ModelItem::getItemExtraFields($row, $item);
// not working. Any ideas?
@phproberto
Copy link

This works:

require_once JPATH_SITE . '/components/com_k2/models/item.php';
require_once JPATH_SITE . '/components/com_k2/helpers/utilities.php';
$id = (int) $item->getId();
$db = JFactory::getDBO();
$query = "SELECT extra_fields FROM #__k2_items WHERE id={$id}";
$db->setQuery($query);
$row = $db->loadObject();
$extrafields = K2ModelItem::getItemExtraFields($row->extra_fields);

@phproberto
Copy link

Forget it. That was an old code that was working for 2.6.1.

Better json_decode yourself as you did :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment