Jump to content

Recommended Posts

Posted

I'm uploading multiple images via the API.

Is there a way to explicitly set the sort order once uploaded?

eg: something like this would be handy:

foreach($files as $order => $f) {
  $p->images->add($f)->sort($order);
}
Posted

Short answer, no.

But there are alphanumeric sort possibilities on run time. As $images is a Wirearray you could do:

$images = $page->images->sort('name');
foreach ($images as $key => $image) {
    echo "$key => " . $image->url . '<br>'; // hyatt2.jpg => /site/assets/files/1/hyatt2.jpg
}

This will, sort the images on filename.

--

And you can re-save the page with the new sort order.

// Page is previously saved, but now we reset the order
$page->images->sort('name');
$page->of(false);
$page->save();
Posted

Does it not make sense to expose the sort field via the API?

Front end example would be drag and drop sorting of user uploaded images.
Having this order saved and mirrored in PW Admin would be ideal.

  • Like 1

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
  • Recently Browsing   0 members

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