I've exported some entries from a database which has given me the following JSON:
[
{
"Artist_Title": "17 Hippies",
"Gallery_Image_Filename": "17Hippies-2011-web.jpg"
},
{
"Artist_Title": "17 Hippies",
"Gallery_Image_Filename": "christo.jpg"
},
{
"Artist_Title": "17 Hippies",
"Gallery_Image_Filename": "kiki1.jpg"
},
{
"Artist_Title": "17 Hippies",
"Gallery_Image_Filename": "17-hippies.jpg"
},
{
"Artist_Title": "17 Hippies",
"Gallery_Image_Filename": "Photo1.jpg"
},
{
"Artist_Title": "Ann Savoy Trio",
"Gallery_Image_Filename": "Savoy-Trio-B&W-resize342x.jpg"
},
{
"Artist_Title": "Baghdaddies",
"Gallery_Image_Filename": "Baghdaddies-(Small).JPG"
},
{
"Artist_Title": "Baghdaddies",
"Gallery_Image_Filename": "Baghdaddies2.jpg"
}
]
Which has gallery images associated against a post. I've exported the Post Title (Artist_Title) and the Image file name (Gallery_Image_Filename).
One post can have multiple gallery images, the end goal here is to do an foreach and var dump a list like for example
wget www.[domain].com/images/17Hippies-2011-web.jpg -O 17-hippies-gallery-1.jpg
wget www.[domain].com/images/christo.jpg -O 17-hippies-gallery-2.jpg
wget www.[domain].com/images/kiki1.jpg -O 17-hippies-gallery-3.jpg
wget www.[domain].com/images/17-hippies.jpg -O 17-hippies-gallery-4.jpg
wget www.[domain].com/images/Photo1.jpg -O 17-hippies-gallery-5.jpg
wget www.[domain].com/images/Savoy-Trio-B&W-resize342x.jpg -O ann-savoy-trio-1.jpg
wget www.[domain].com/images/Baghdaddies-(Small).JPG -O baghdaddies-gallery-1.jpg
wget www.[domain].com/images/Baghdaddies2.jpg -O 17-baghdaddies-gallery-2.jpg
So essentially I am creating a wget list of image urls along with a new file name for them. I'm taking the post title, sanitising it, appending -gallery-[number], where the number needs to match the amount of Artist_Title's it has found.
I have this foreach loop, I just need to amend it to add the -[number] based on amount of posts now
foreach($gallery as $image) {
echo 'wget https://www.accessallareas.info/images/' . $image->Gallery_Image_Filename . ' -O ' . sanitize_title($image->Article_Title) . '-gallery.jpg';
echo '<br>';
}
Is this achievable?