Jump to content
Sign in to follow this  
ngrmm

order fields by name

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?

Share this post


Link to post
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

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...