In a FrontController I’m using a function to get post meta data & append it to the post:
array_map([$this,'getPostMeta'],$wp_query->posts);
Now I need the same function in other controllers so I moved the getPostMeta-Function in a Trait (Controllers/Partials/PostMetaData.php) and added the use App\Controllers\Partials\PostMetaData;
Statement under the use “Sober\Controller…” in the FrontController.
Using a for-loop:
for($i = 0; $i < $wp_query->post_count; $i++) {
$wp_query->posts[$i] = PostMetaData::getPostMeta($wp_query->posts[$i]);
}
everything works fine.
But I can’t get it work using array_map()
. I tried:
-
array_map(['PostMetaData::getPostMeta'],$wp_query->posts);
-
array_map(['PostMetaData', 'getPostMeta'], $wp_query->posts);
But none of the above works.
Thanks in advance for any help!