New to Blade: Issue with Array Map and CPT

A controller applies to the entire endpoint it sits on top of. In this case, the controller for an archive sits on the archive endpoint.

get_field() accepts two arguments; the field name, and the post ID (or options if it’s a site option). If you call it without the second argument, it attempts to get the ID of the current post. It can only do this if there is a current post.

When you call get_field() without an ID argument on an archive controller, there is no “current post” for it to get, because there is no post ID associated with an archive endpoint. That means it returns false (or null, or some other error return value), which is obviously not the array that array_map() expects.

What you are doing wrong is calling get_field() on an archive, instead of calling it on each post that is displayed on the archive.

One way to do this is to generate an array in your archive controller for each post on the current archive page, and then do all the logic you need to on each post at that time. I’ve posted an example of that technique here: The right way to run multiple WordPress loops