Skip to content
Grav 2.0 is officially stable. Read the announcement →

Community guidelines

Please keep discussions civil and on-topic. Repeated violations may lead to a temporary ban.

Plugins

Fetching all pages with taxonomy in plugin

Started by P. Fighter 8 years ago · 1 replies · 566 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 Rene, 1 week ago
2 43 1 week ago
Plugins · by Xavier, 4 weeks ago
2 53 4 weeks ago
Plugins · by Luka Prinčič, 7 years ago
3 1179 1 month ago
Plugins · by Sebastian van de Meer, 1 month ago
1 48 1 month ago
Plugins · by PIERROT Alain, 2 months ago
3 72 2 months ago