Skip to content
Grav 2.1 is out: every page speaks Markdown. Read the announcement →

Fetching all pages with taxonomy in plugin

Started by P. Fighter 8 years ago · 1 replies · 732 views
8 years ago

I'm trying to iterate through all pages with a specific tag. Right now, my code looks like this:

PHP
$pages = \Grav\Common\Grav::instance()['taxonomy'];
$pages =  $pages->findTaxonomy(['tag']);

The docs dictate that the Taxonomy class' findTaxonomy function Returns a new Page object with the sub-pages containing all the values set for a particular taxonomy.

So, that makes me think that I need to utilize the Page class' children function to fetch the pages like so:

$children = $pages->children();

And I would then be able to iterate through the pages and treat those as Page objects.

But running a foreach loop over $children yields an error (An exception has been thrown during the rendering of a template ("Invalid argument supplied for foreach()").). Looping over $pages yields nothing. The tag I search for has been assigned to pages for testing.

To be perfectly honest, I'm kinda fumbling in the dark. Is the taxonomy class even assigned correctly? What am I doing wrong?

Suggested topics

Topic Participants Replies Views Activity
Plugins · by complanar, 2 weeks ago
2 250 4 days ago
Plugins · by Vladimir Novak, 1 month ago
3 594 1 month ago
Plugins · by Mathieu Lecouturier, 2 months ago
3 416 2 months ago
Plugins · by Slebeig, 2 months ago
1 530 2 months ago
Plugins · by Rene, 3 months ago
2 730 3 months ago