Jump to content

add image tags to upload


pmichaelis
 Share

Recommended Posts

Hey,

I would like to add tags to an image field upload via api. Does anybody have some information on that?

im using the following code to update images on a page. 

# remove images
if(count($page->images)) {
  $page->images->deleteAll();
  $page->save();
}

# upload images
foreach($product->image as $image) {
  $page->images->add($image->url);
  $page->images->tags = ? // not working
}

$page->save();

During Page Update the backend says:
Session: Item 'tags' set to ProcessWire\Pageimages is not an allowed type

Thanks for help.

Link to comment
Share on other sites

Hi, if I'm not mistaking, the tags are added to the image:

# upload images
foreach($product->image as $image) {
  $image->tags = "tag1 tag2";
  $page->images->add($image); //assuming $image is already a PageImage?
}

The imagefield itself can only be used to query the tags of the images then:

//e.g.
$page->images->findTag('tag1');    

Hope this helps

Link to comment
Share on other sites

Hey Sebii,

thanks for your help, but I could not figure it out.

foreach($product->image as $image) {
  $image->tags = "tag1 tag2";
  $page->images->add($image->url);
}

$product->imgae is an external array of images. It has nothing to do with the page images. So there is nothing like $image->tags. 

Link to comment
Share on other sites

Hi sorry, it looked like it is already coming from a different imagefield.

foreach($product->image as $image) {
  $pageimage = new PageImage($page->images, $image->url); 
  $pageimage->tags = "tag1 tag2";
  $page->images->add($pageimage);
}

Edit: Woops, too slow and too much fiddeling. See the answer above... :)

Edited by Sebii
  • 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

×
×
  • Create New...