1

What is the most straightforward way to get the current category in the view? I notice that there is a getTerm method in the Term class:

public function getEntity()
{
    return $this->getTerm();
}

/**
 * Returns the current Wordpress category
 * This is just a wrapper for getCurrentCategory()
 *
 * @return \FishPig\WordPress\Model\Term
 */
public function getTerm()
{
    if (!$this->hasTerm()) {
        $this->setTerm($this->_registry->registry(Term::ENTITY));
    }

    return $this->_getData('term');
}

However if I try to utilize the method within a template (for example, the default post list wrapper.phtml template which utilizes the Term block in the layout) it throws an error:

<?php echo $this->getTerm() ?>

Recoverable Error: Object of class FishPig\WordPress\Model\Term could not be converted to string in

I'm probably just missing something simple, any help would be greatly appreciated. Thanks!

Speencer
  • 13
  • 2

1 Answers1

1
$term = \Magento\Framework\App\ObjectManager::getInstance()
          ->get('Magento\Framework\Registry')
          ->registry('wordpress_term');
Ben Tideswell
  • 1,697
  • 2
  • 11
  • 14
  • Thanks! And for anyone else who might be interested, just call `getName()` on the $term object to get the category name. – Speencer Jun 18 '18 at 15:33