Forum
Pass array into perch_content_custom each function
Hi!
I'm trying to pass an array into the perch_content_custom so I can then edit some values in each item, something like this
$result /*the array I want to use*/
perch_content_custom('Destaques',['template' => $template,'count'=>$limit,
'each' => function($item) {
global $index;
$index = ((isset($index)) ? ($index+1) : 0 );
// process as necessary, then return the modified array\
$item['link'] = $result[$index]["permalink_url"];
$item['text'] = $result[$index]["message"];
$item['data'] = $result[$index]["created_time"];
$item['image'] = $result[$index]["full_picture"];
return $item;
}
]);
Is it possible?
Hello Gustavo,
You have to use the
use
keyword: https://php.net/manual/en/functions.anonymous.phpThank you ;)