Reputation: 150
I'm trying to get all of the images inside a specific sub-directory within the Wordpress
uploads
directory, and then output all of those images.
$upload_dir = wp_upload_dir();
$logo_dir = ( $upload_dir['baseurl'] . '/logos/' );
echo $logo_dir . '-----<br />';
$images = glob($logo_dir . "*.PNG");
foreach($images as $image)
{
echo $image;
}
$logo_dir
is outputting the correct directory. I'm not sure what I'm doing wrong with the foreach
.
Any help? Thanks!
Upvotes: 3
Views: 4058
Reputation: 98901
Change:
$logo_dir = ( $upload_dir['baseurl'] . '/logos/' );
to
$logo_dir = ( $upload_dir['basedir'] . '/logos/' );
https://codex.wordpress.org/Function_Reference/wp_upload_dir
Update based on your comments:
foreach($images as $image)
{
$filename = basename($image);
echo $upload_dir['baseurl']."/$filename";
}
Upvotes: 1