Hello,
I want to find all the pages with a custom variable in the frontmatter, in php.
Here's some pages frontmatters:
---
news:
location:
- New York
link: http://kufhlskjflkdjfhls
---
---
news:
location:
- New York
- Chicago
link: http://klmlmlmlkkkkmkmk
---
---
news:
location:
- Amsterdam
link: http://qsssssszzszszszszszs
---
I want to find the pages where "New York" is a location.
Have you got an idea ?
I can do something like that
$collection = new Collection();
foreach( $all_pages as $p )
{
$header = $p->header();
if(
$header
&& property_exists( $header, 'news' )
&& array_key_exists( 'location', $header->news )
&& in_array( 'New York', $header->news['location'] )
)
{
$collection->append( $p );
}
}
but I don't know how to get all the pages first ! This is silly.
And I have the feeling that something easier could be done. With $page->evaluate(...) maybe ?
Thank you for any tip. I will also appreciate any relevant link to the documentation.
P.S: A convenient solution could be to make this "location" field a part of the taxonomy. But it bother me that this taxonomy field will appear in the admin settings form, for every page, including the pages where this field make no sense.