Jump to content

order fields by name


ngrmm
 Share

Recommended Posts

i want to output some of my pagefields as options in a html select tag
i can do this this way:

$search_options = $templates->get("catalog_item")->fields;

but i'm not able to sort them:

$search_options = $templates->get("catalog_item")->fields("sort=label");

array_multisort() ksort() doesn't work either. is sort limited to pagearrays?

Link to comment
Share on other sites

you could try something like:

$search_options = $templates->get("project")->fields;
$fieldNames = array();
foreach($search_options as $so) {
    $fieldNames[] = $so->name;
}
sort($fieldNames);

afaik, $search_options is an object, not an array.

  • Like 1
Link to comment
Share on other sites

1 hour ago, ngrmm said:

is sort limited to pagearrays?

You can use sort() on WireArray derived objects :

$search_options = $templates->get("catalog_item")->fields->sort("label"); // or sort("-label")

 

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