Jump to content

Use PageArray as a selector?


yellowled
 Share

Recommended Posts

Current project has news posts which are supposed to be associated with one or more sections of the site. So the template news-posts uses a field news_sections, which uses the fieldtype Page/Multiple Pages.

Now, on the index page of any given section (which are child pages of Home), I would like to emit a list of recent news posts associated with said section, limited to 5 posts. However, I can't figure out a way to use the news_sections field as a selector. The basic API call for this should be something like this:

$news = $pages->find("template=news-post, limit=5");

so my idea was to use something like

$sectionId = $page->id;
$news = $pages->find("template=news-post, news_section*=$sectionId, limit=5");

but that doesn't work because the field type doesn't accept *= as a selector operator. Am I doing it wrong or is this fieldtype simply not meant to be used in a selector?

Link to comment
Share on other sites

The page fieldtype refers to the page object itself, and not the id. So this should work:

$news = $pages->find("template=news-post, news_section=$page, limit=5");
  • Like 4
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...