Jump to content

Foreach all values from the field


xxxlogiatxxx
 Share

Recommended Posts

Hey guys. Need some little help for a newbie. How can i foreach all possible values from existing field of a child template into select form? Trying like this but it showing me results from created pages and their fields.

  $fields = $page->find("template=item, sort=item_type");

  echo "<select>";
  foreach($fields as $item) {
    echo "
      <option>{$item->item_type->title}</option>
    ";
  }
  echo "</select>";

 

Link to comment
Share on other sites

@Gideon So, there is indeed a $page->find() method:

Quote

This is the same as Pages::find() except that the results are limited to descendents of this Page.

https://processwire.com/api/ref/page/find/

 

@xxxlogiatxxx, I've read your question a couple of times but I can't work out what you are trying to do. You populate a variable you have called $fields. Firstly, you should choose a different name for this variable because $fields is the name of an API variable: https://processwire.com/api/ref/fields/

Secondly, you populate this variable from $page->find() and the result of this will be pages not fields. Can explain more about what your aim is?

 

  • Like 2
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

×
×
  • Create New...