title: How to display Extra Fields from Joomla K2
body: <p>I have this bit of code I am using to get the information from the k2_items table in the database, but all I get for the extra_fields is a JSON string and not the human readable id/values I need to print.</p>
  
  <p>Here is the code I'm using to display the database information, and the attempted code to pull the extra_fields values.</p>
  
  <pre><code>&lt;?php
  
  
  define( '_JEXEC', 1 );
  define( 'JPATH_BASE', realpath(dirname(__FILE__).'' ));
  define( 'DS', DIRECTORY_SEPARATOR );
  
  require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
  require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );
  $mainframe =&amp; JFactory::getApplication('site');
  $mainframe-&gt;initialise();
  
  
  
  
  
    $user = JFactory::getUser();
  
  
    $session =&amp; JFactory::getSession();
    $user = JFactory::getUser();
  
    //echo 'Username is ' . $user-&gt;username;
  
  
  
  
  
    if($user-&gt;username === NULL)
    //user is not logged in
    {
          exit('You are not authorized to view this page. &lt;a href = "' . JURI::root() . '"&gt;Please return to the homepage and login using the proper username/password.&lt;/a&gt;' . $user-&gt;username);
  
  
    }
    else
    //user is logged in
    {
  
      echo "&lt;p&gt;Welcome $user-&gt;username&lt;/p&gt;";
      echo '&lt;p&gt;&lt;a href = "http://ac.tradewindus.com/index.php?option=com_content&amp;view=featured&amp;Itemid=143"&gt;Go here to log out&lt;/a&gt;&lt;/p&gt;';
    $db=JFactory::getDBO();
      $sql="SELECT * FROM #__k2_items WHERE published='1'";
      $db-&gt;setQuery($sql);
      $list=$db-&gt;loadObjectList();
  
  
  
      foreach($list as $item)
      {
          echo "&lt;pre&gt;";
          echo print_r($item, true);
          echo "&lt;/pre&gt;";
  
      //convertArray to use ids as key
      $extrafields = array();
      foreach($item-&gt;extra_fields as $item)
      {
      $extrafields[$item-&gt;id] = $item-&gt;value;
      }
  
      echo $extrafields[1];
      echo $extrafields[2];
      echo $extrafields[3];
      echo $extrafields[4];
      echo $extrafields[5];
  
          //echo "&lt;p&gt;Title: $item-&gt;title&lt;/p&gt;";
          //echo $item-&gt;introtext;
    }
  }
  
  ?&gt;
  </code></pre>
  
  <p>And this is the result of what I get for each "foreach" loop output.</p>
  
  <pre><code>stdClass Object
  (
      [id] =&gt; 83
      [title] =&gt; SPEC SHEET: PANORAMAH 38 SASH BI-RAIL
      [alias] =&gt; spec-sheet-panoramah-38-sash-birail
      [catid] =&gt; 4
      [published] =&gt; 1
      [introtext] =&gt; 
  
  SPEC SHEET: PANORAMAH 38 SASH BI-RAIL
  
      [fulltext] =&gt; 
      [video] =&gt; 
      [gallery] =&gt; 
      [extra_fields] =&gt; [{"id":"1","value":""},{"id":"2","value":["1"]},{"id":"3","value":["4"]},{"id":"4","value":["1","2"]},{"id":"5","value":["7"]},{"id":"6","value":["4"]}]
      [extra_fields_search] =&gt;  PanoramAH  Minimal Frame  Door Window  Sliding  Spec Sheets  
      [created] =&gt; 2014-01-09 00:00:00
      [created_by] =&gt; 550
      [created_by_alias] =&gt; 
      [checked_out] =&gt; 0
      [checked_out_time] =&gt; 0000-00-00 00:00:00
      [modified] =&gt; 2014-08-06 22:44:57
      [modified_by] =&gt; 550
      [publish_up] =&gt; 2014-01-09 00:00:00
      [publish_down] =&gt; 0000-00-00 00:00:00
      [trash] =&gt; 0
      [access] =&gt; 1
      [ordering] =&gt; 14
      [featured] =&gt; 0
      [featured_ordering] =&gt; 0
      [image_caption] =&gt; 
      [image_credits] =&gt; 
      [video_caption] =&gt; 
      [video_credits] =&gt; 
      [hits] =&gt; 0
      [params] =&gt; {"catItemTitle":"","catItemTitleLinked":"","catItemFeaturedNotice":"","catItemAuthor":"","catItemDateCreated":"","catItemRating":"","catItemImage":"","catItemIntroText":"","catItemExtraFields":"","catItemHits":"","catItemCategory":"","catItemTags":"","catItemAttachments":"","catItemAttachmentsCounter":"","catItemVideo":"","catItemVideoWidth":"","catItemVideoHeight":"","catItemAudioWidth":"","catItemAudioHeight":"","catItemVideoAutoPlay":"","catItemImageGallery":"","catItemDateModified":"","catItemReadMore":"","catItemCommentsAnchor":"","catItemK2Plugins":"","itemDateCreated":"","itemTitle":"","itemFeaturedNotice":"","itemAuthor":"","itemFontResizer":"","itemPrintButton":"","itemEmailButton":"","itemSocialButton":"","itemVideoAnchor":"","itemImageGalleryAnchor":"","itemCommentsAnchor":"","itemRating":"","itemImage":"","itemImgSize":"","itemImageMainCaption":"","itemImageMainCredits":"","itemIntroText":"","itemFullText":"","itemExtraFields":"","itemDateModified":"","itemHits":"","itemCategory":"","itemTags":"","itemAttachments":"","itemAttachmentsCounter":"","itemVideo":"","itemVideoWidth":"","itemVideoHeight":"","itemAudioWidth":"","itemAudioHeight":"","itemVideoAutoPlay":"","itemVideoCaption":"","itemVideoCredits":"","itemImageGallery":"","itemNavigation":"","itemComments":"","itemTwitterButton":"","itemFacebookButton":"","itemGooglePlusOneButton":"","itemAuthorBlock":"","itemAuthorImage":"","itemAuthorDescription":"","itemAuthorURL":"","itemAuthorEmail":"","itemAuthorLatest":"","itemAuthorLatestLimit":"","itemRelated":"","itemRelatedLimit":"","itemRelatedTitle":"","itemRelatedCategory":"","itemRelatedImageSize":"","itemRelatedIntrotext":"","itemRelatedFulltext":"","itemRelatedAuthor":"","itemRelatedMedia":"","itemRelatedImageGallery":"","itemK2Plugins":""}
      [metadesc] =&gt; 
      [metadata] =&gt; robots=
  author=
      [metakey] =&gt; 
      [plugins] =&gt; 
      [language] =&gt; *
  )
  </code></pre>
  
  <p>The Extra Fields should be showing at the very bottom of this, but I guess nothing is being returned. When extra_fields is printed in the db output, the values are numbers like [1]; but when I look at the K2 backend, they are text answers or dropdown selections; human readable. I'm not really a Joomla developer so I don't know if there is some kind of JRegistry thing or something I should be using, but I would appreciate being pointed in the right direction. :D</p>