Best way to upload images by url on the backend?
-
I’m building a plugin that will import some data from a third-party API.
I have an array like
$listings = json_decode(' "@odata.count": 986, "value": [ { "@odata.id": "Property(6108754)", "City": "Reedsport", "ListPrice": 99950.0, "ListingKey": "6108754", "PropertySubType": "SingleFamilyResidence", "YearBuilt": null, "Media": [ { "MediaURL": "image.com/image.jpg" }, { "MediaURL": "image.com/image.jpg" } ] ] }')I have a foreach loop like
foreach($listings->value as $listing) {
foreach($listing->Media as $image){
media_sideload_image($image->MediaURL);
}
/* the rest of the code to bring in the other field values */
}
The problem is the nested foreach loop to bring in the image breaks the site. If I remove the foreach loop for the images, the rest of the code works as expected.
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
The topic ‘Best way to upload images by url on the backend?’ is closed to new replies.