Jump to content

finding a repeater in pages by repeater subfield


jon9china
 Share

Recommended Posts

I want to return a repeater object in my pages by matching the value of a field within the repeater.  In docs, it says repeater can be treated like a page, but what does that mean for this sort of case?

for example, my repeater might be named:  'word_object', which includes fields 'this_word', 'definition', etc.

and i want to return a word_object where the field 'this_word' == 'apple'

Link to comment
Share on other sites

To find all pages where the repeater field word_object has a field this_word with value apple you can use subfield selectors

$pageArray = $pages->find("word_object.this_word=apple")

This will return a PageArray with all those pages.

Now to get all the word_object repeater fields from this PageArray, you can use the  WireArray explode method

$repeatersArray = $pageArray->explode("word_object")

This will return an array with all the repeater fields. You can now foreach through this array and output whatever you need.

You could also chain this to a single operation

$repeatersArray = $pages->find("word_object.this_word=apple")->explode("word_object")

 

  • 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...