title: PHP joomla get metadata in com_content
body: <p>I am trying to access the metadata in an article I made. The article is being displayed under a menu item called News->website news which is a blog layout. go to the link of the article from the blog view (and other areas), I can't seem to access the metadata info.</p>
  
  <p>I am using an override for the view.html for all categories in the com_content.</p>
  
  <p>The reason why I was doing this is so that I can control each article, category and menus (I think I did menu) OG tags based on their description. The image part is because in the backend under metadata I added a field to select the image you want. My code reverts to what is set in $configuration file based on what you hard code put in there. Anyways, my code seems to only be showing me variables in OG for whats in the config file, except the title.</p>
  
  <p>my code is like this for categories:
  //(lol) all the code is in the area that says og tags.</p>
  
  <pre><code>&lt;?php
  </code></pre>
  
  <p>/**  * @package     Joomla.Site  * @subpackage  com_content  * @copyright   Copyright (C) 2005 - 2014 Open Source Matters, Inc. All rights reserved.  * @license        GNU General Public License version 2 or later; see LICENSE.txt  */
  defined('_JEXEC') or die;
  /**  * HTML View class for the Content component  *  * @package     Joomla.Site  * @subpackage  com_content  * @since 1.5  */
  class ContentViewCategory extends JViewLegacy</p>
  
  <pre><code>{
  protected $state;
  protected $items;
  protected $category;
  protected $children;
  protected $pagination;
  protected $lead_items = array();
  protected $intro_items = array();
  protected $link_items = array();
  protected $columns = 1;
  function display($tpl = null)
      {
      $app = JFactory::getApplication();
      $user = JFactory::getUser();
  
      // Get some data from the models
  
      $state = $this-&gt;get('State');
      $params = $state-&gt;params;
      $items = $this-&gt;get('Items');
      $category = $this-&gt;get('Category');
      $children = $this-&gt;get('Children');
      $parent = $this-&gt;get('Parent');
      $pagination = $this-&gt;get('Pagination');
  
      // Check for errors.
  
      if (count($errors = $this-&gt;get('Errors')))
          {
          JError::raiseError(500, implode("\n", $errors));
          return false;
          }
  
      if ($category == false)
          {
          return JError::raiseError(404, JText::_('JGLOBAL_CATEGORY_NOT_FOUND'));
          }
  
      if ($parent == false)
          {
          return JError::raiseError(404, JText::_('JGLOBAL_CATEGORY_NOT_FOUND'));
          }
  
      // Setup the category parameters.
  
      $cparams = $category-&gt;getParams();
      $category-&gt;params = clone ($params);
      $category-&gt;params-&gt;merge($cparams);
  
      // Check whether category access level allows access.
  
      $user = JFactory::getUser();
      $groups = $user-&gt;getAuthorisedViewLevels();
      if (!in_array($category-&gt;access, $groups))
          {
          return JError::raiseError(403, JText::_('JERROR_ALERTNOAUTHOR'));
          }
  
      // PREPARE THE DATA
      // Get the metrics for the structural page layout.
  
      $numLeading = $params-&gt;def('num_leading_articles', 1);
      $numIntro = $params-&gt;def('num_intro_articles', 4);
      $numLinks = $params-&gt;def('num_links', 4);
  
      // Compute the article slugs and prepare introtext (runs content plugins).
  
      for ($i = 0, $n = count($items); $i &lt; $n; $i++)
          {
          $item = &amp; $items[$i];
          $item-&gt;slug = $item-&gt;alias ? ($item-&gt;id . ':' . $item-&gt;alias) : $item-&gt;id;
  
          // No link for ROOT category
  
          if ($item-&gt;parent_alias == 'root')
              {
              $item-&gt;parent_slug = null;
              }
  
          $item-&gt;catslug = $item-&gt;category_alias ? ($item-&gt;catid . ':' . $item-&gt;category_alias) : $item-&gt;catid;
          $item-&gt;event = new stdClass();
          $dispatcher = JDispatcher::getInstance();
  
          // Old plugins: Ensure that text property is available
  
          if (!isset($item-&gt;text))
              {
              $item-&gt;text = $item-&gt;introtext;
              }
  
          JPluginHelper::importPlugin('content');
          $results = $dispatcher-&gt;trigger('onContentPrepare', array(
              'com_content.category', &amp;$item, &amp;$this-&gt;params,
              0
          ));
  
          // Old plugins: Use processed text as introtext
  
          $item-&gt;introtext = $item-&gt;text;
          $results = $dispatcher-&gt;trigger('onContentAfterTitle', array(
              'com_content.category', &amp;$item, &amp;$item-&gt;params,
              0
          ));
          $item-&gt;event-&gt;afterDisplayTitle = trim(implode("\n", $results));
          $results = $dispatcher-&gt;trigger('onContentBeforeDisplay', array(
              'com_content.category', &amp;$item, &amp;$item-&gt;params,
              0
          ));
          $item-&gt;event-&gt;beforeDisplayContent = trim(implode("\n", $results));
          $results = $dispatcher-&gt;trigger('onContentAfterDisplay', array(
              'com_content.category', &amp;$item, &amp;$item-&gt;params,
              0
          ));
          $item-&gt;event-&gt;afterDisplayContent = trim(implode("\n", $results));
          }
  
      // Check for layout override only if this is not the active menu item
      // If it is the active menu item, then the view and category id will match
  
      $active = $app-&gt;getMenu()-&gt;getActive();
      if ((!$active) || ((strpos($active-&gt;link, 'view=category') === false) || (strpos($active-&gt;link, '&amp;id=' . (string)$category-&gt;id) === false)))
          {
  
          // Get the layout from the merged category params
  
          if ($layout = $category-&gt;params-&gt;get('category_layout'))
              {
              $this-&gt;setLayout($layout);
              }
          }
  
      // At this point, we are in a menu item, so we don't override the layout
  
      elseif (isset($active-&gt;query['layout']))
          {
  
          // We need to set the layout from the query in case this is an alternative menu item (with an alternative layout)
  
          $this-&gt;setLayout($active-&gt;query['layout']);
          }
  
      // For blog layouts, preprocess the breakdown of leading, intro and linked articles.
      // This makes it much easier for the designer to just interrogate the arrays.
  
      if (($params-&gt;get('layout_type') == 'blog') || ($this-&gt;getLayout() == 'blog'))
          {
          $max = count($items);
  
          // The first group is the leading articles.
  
          $limit = $numLeading;
          for ($i = 0; $i &lt; $limit &amp;&amp; $i &lt; $max; $i++)
              {
              $this-&gt;lead_items[$i] = &amp; $items[$i];
              }
  
          // The second group is the intro articles
  
           . $limit = $numLeading + $numIntro;
  
          // Order articles across, then down (or single column mode)
  
          for ($i = $numLeading; $i &lt; $limit &amp;&amp; $i &lt; $max; $i++)
              {
              $this-&gt;intro_items[$i] = &amp; $items[$i];
              }
  
          $this-&gt;columns = max(1, $params-&gt;def('num_columns', 1));
          $order = $params-&gt;def('multi_column_order', 1);
          if ($order == 0 &amp;&amp; $this-&gt;columns &gt; 1)
              {
  
              // call order down helper
  
              $this-&gt;intro_items = ContentHelperQuery::orderDownColumns($this-&gt;intro_items, $this-&gt;columns);
              }
  
          $limit = $numLeading + $numIntro + $numLinks;
  
          // The remainder are the links.
  
          for ($i = $numLeading + $numIntro; $i &lt; $limit &amp;&amp; $i &lt; $max; $i++)
              {
              $this-&gt;link_items[$i] = &amp; $items[$i];
              }
          }
  
      $children = array(
          $category-&gt;id =&gt; $children
      );
  
      // Escape strings for HTML output
  
      $this-&gt;pageclass_sfx = htmlspecialchars($params-&gt;get('pageclass_sfx'));
      $this-&gt;maxLevel = $params-&gt;get('maxLevel', -1);
      $this-&gt;assignRef('state', $state);
      $this-&gt;assignRef('items', $items);
      $this-&gt;assignRef('category', $category);
      $this-&gt;assignRef('children', $children);
      $this-&gt;assignRef('params', $params);
      $this-&gt;assignRef('parent', $parent);
      $this-&gt;assignRef('pagination', $pagination);
      $this-&gt;assignRef('user', $user);
      $this-&gt;_prepareDocument();
      parent::display($tpl);
      }
  
  /**      * Prepares the document     */
  protected
  function _prepareDocument()
      {
      $app = JFactory::getApplication();
      $menus = $app-&gt;getMenu();
      $pathway = $app-&gt;getPathway();
      $title = null;
  
      // Because the application sets a default page title,
      // we need to get it from the menu item itself
  
      $menu = $menus-&gt;getActive();
      if ($menu)
          {
          $this-&gt;params-&gt;def('page_heading', $this-&gt;params-&gt;get('page_title', $menu-&gt;title));
          }
        else
          {
          $this-&gt;params-&gt;def('page_heading', JText::_('JGLOBAL_ARTICLES'));
          }
  
      $id = (int)@$menu-&gt;query['id'];
      if ($menu &amp;&amp; ($menu-&gt;query['option'] != 'com_content' || $menu-&gt;query['view'] == 'article' || $id != $this-&gt;category-&gt;id))
          {
          $path = array(
              array(
                  'title' =&gt; $this-&gt;category-&gt;title,
                  'link' =&gt; ''
              )
          );
          $category = $this-&gt;category-&gt;getParent();
          while (($menu-&gt;query['option'] != 'com_content' || $menu-&gt;query['view'] == 'article' || $id != $category-&gt;id) &amp;&amp; $category-&gt;id &gt; 1)
              {
              $path[] = array(
                  'title' =&gt; $category-&gt;title,
                  'link' =&gt; ContentHelperRoute::getCategoryRoute($category-&gt;id)
              );
              $category = $category-&gt;getParent();
              }
  
          $path = array_reverse($path);
          foreach($path as $item)
              {
              $pathway-&gt;addItem($item['title'], $item['link']);
              }
          }
  
      $title = $this-&gt;params-&gt;get('page_title', '');
      if (empty($title))
          {
          $title = $app-&gt;getCfg('sitename');
          }
      elseif ($app-&gt;getCfg('sitename_pagetitles', 0) == 1)
          {
          $title = JText::sprintf('JPAGETITLE', $app-&gt;getCfg('sitename') , $title);
          }
      elseif ($app-&gt;getCfg('sitename_pagetitles', 0) == 2)
          {
          $title = JText::sprintf('JPAGETITLE', $title, $app-&gt;getCfg('sitename'));
          }
  
      $this-&gt;document-&gt;setTitle($title);
      $this-&gt;document-&gt;setTitle($title);
  
      // #####################ADDS OG TAGS##############################
  
      $this-&gt;document-&gt;addCustomTag('&lt;meta property="og:site_name" content="ClearLove" /&gt;');
      $this-&gt;document-&gt;addCustomTag('&lt;meta property="og:title" content="' . $title . '" /&gt;');
      $this-&gt;document-&gt;addCustomTag('&lt;meta property="og:url" content="' . JURI::current() . '" /&gt;');
      if ($this-&gt;category-&gt;ogimages)
          {
          $ogimages = $this-&gt;category-&gt;ogimages;
          }
      elseif (!$this-&gt;category-&gt;ogimages &amp;&amp; $this-&gt;params-&gt;get('menu-meta_ogimages'))
          {
          $ogimages = $this-&gt;params-&gt;get("menu-meta_ogimages");
          }
      elseif ($app-&gt;getCfg("ogimages"))
          {
          $ogimages = $app-&gt;getCfg("ogimages");
          }
  
      // #####################ADDS OG TAGS FOR DESC##############################
  
      if ($this-&gt;category-&gt;metadesc)
          {
          $this-&gt;document-&gt;setDescription($this-&gt;category-&gt;metadesc);
          $this-&gt;document-&gt;addCustomTag('&lt;meta property="og:description" content="' . $this-&gt;category-&gt;metadesc . '" /&gt;');
          }
      elseif (!$this-&gt;category-&gt;metadesc &amp;&amp; $this-&gt;params-&gt;get('menu-meta_description'))
          {
          $this-&gt;document-&gt;setDescription($this-&gt;params-&gt;get('menu-meta_description'));
          $this-&gt;document-&gt;addCustomTag('&lt;meta property="og:description" content="' . $this-&gt;params-&gt;get("menu-meta_description") . '" /&gt;');
          }
      elseif ($app-&gt;getCfg("MetaDesc"))
          {
          $this-&gt;document-&gt;addCustomTag('&lt;meta property="og:description" content="' . $app-&gt;getCfg("MetaDesc") . '" /&gt;');
          }
  
      // #####################ADDS OG TAGS FOR IMAGE##############################
  
      if (!preg_match("/http:\/\//", $ogimages) &amp;&amp; !("www." == substr($ogimages, 0, 4)) &amp;&amp; $ogimages)
          {
          $ogimages = 'http://www.clearlove.ca/' . $ogimages;
          }
  
      if ($ogimages)
          {
          $ogimage_atribs = getimagesize($ogimages);
          $this-&gt;document-&gt;addCustomTag('&lt;meta property="og:image" content="' . $ogimages . '" /&gt;');
          $this-&gt;document-&gt;addCustomTag('&lt;meta property="og:image:type" content="' . image_type_to_mime_type($ogimage_atribs[2]) . '" /&gt;');
          $this-&gt;document-&gt;addCustomTag('&lt;meta property="og:image:width" content="' . $ogimage_atribs[0] . '" /&gt;');
          $this-&gt;document-&gt;addCustomTag('&lt;meta property="og:image:height" content="' . $ogimage_atribs[1] . '" /&gt;');
          }
  
      // #####################DONE ADDING TAGS##############################
  
      if ($this-&gt;category-&gt;metakey)
          {
          $this-&gt;document-&gt;setMetadata('keywords', $this-&gt;category-&gt;metakey);
          }
      elseif (!$this-&gt;category-&gt;metakey &amp;&amp; $this-&gt;params-&gt;get('menu-meta_keywords'))
          {
          $this-&gt;document-&gt;setMetadata('keywords', $this-&gt;params-&gt;get('menu-meta_keywords'));
          }
  
      if ($this-&gt;params-&gt;get('robots'))
          {
          $this-&gt;document-&gt;setMetadata('robots', $this-&gt;params-&gt;get('robots'));
          }
  
      if ($app-&gt;getCfg('MetaAuthor') == '1')
          {
          $this-&gt;document-&gt;setMetaData('author', $this-&gt;category-&gt;getMetadata()-&gt;get('author'));
          }
  
      $mdata = $this-&gt;category-&gt;getMetadata()-&gt;toArray();
      foreach($mdata as $k =&gt; $v)
          {
          if ($v)
              {
              $this-&gt;document-&gt;setMetadata($k, $v);
              }
          }
  
      // Add feed links
  
      if ($this-&gt;params-&gt;get('show_feed_link', 1))
          {
          $link = '&amp;format=feed&amp;limitstart=';
          $attribs = array(
              'type' =&gt; 'application/rss+xml',
              'title' =&gt; 'RSS 2.0'
          );
          $this-&gt;document-&gt;addHeadLink(JRoute::_($link . '&amp;type=rss') , 'alternate', 'rel', $attribs);
          $attribs = array(
              'type' =&gt; 'application/atom+xml',
              'title' =&gt; 'Atom 1.0'
          );
          $this-&gt;document-&gt;addHeadLink(JRoute::_($link . '&amp;type=atom') , 'alternate', 'rel', $attribs);
          }
      }
  }
  </code></pre>