user3431511
user3431511

Reputation: 1

Error in using glob function with wordpress

is the following ... To trying to retrieve images from a folder eat the native php function glob, only that is returning an empty array ... and I'm passing the full path to the folder function ...

$pasta = get_template_directory_uri() . '/img/projetos/' . get_post_meta($post->ID, 'projeto', true) .'/';              

$imagens = glob("$pasta{*jpg,*png}", GLOB_BRACE) or die ("Erro ao acessar $pasta");

Upvotes: 0

Views: 105

Answers (1)

Jaykumar Patel
Jaykumar Patel

Reputation: 27614

You missing to * any of image file, You are passing full path of folder but you missing to which are file you want to take thats why use * all jpg and png extension file, Try this way,

$pasta = get_template_directory_uri() . '/img/projetos/' . get_post_meta($post->ID, 'projeto', true) .'/';              

$imagens = glob("$pasta . "*. {jpg,png}", GLOB_BRACE) or die ("Erro ao acessar $pasta");

Upvotes: 1

Related Questions