We have a custom post type called our_models
to display models from a series of a product.
We’re still learning and trying to wrap our heads around Blade Controllers, etc.
So we have a controllers setup to work with ACF in App.php
:
public function models()
{
return array_map(function($model) {
return [
'title' => $model['model_type_name'] ?? null,
'description' => $model['short_description'] ?? null,
'image' => $model['image'],
'aluminum' => $model['aluminum_colors'] ?? null,
'poly' => $model['poly_roof_colors'] ?? null,
'heat' => $model['heat_poly_roof_colors'] ?? null,
'wind' => $model['wind_pressure'] ?? null,
'snow' => $model['snow_load'] ?? null,
];
}, get_field('model_series') ?? []);
}
This works great for individual posts under our post type without error and displays all the data just fine but when we’re visiting the archive for for our_models
, we receive the following PHP error:
Warning: array_map(): Expected parameter 2 to be an array, bool given in /srv/www/website.com/current/web/app/themes/website/app/Controllers/App.php on line 89
which focuses on this line:
}, get_field('model_series') ?? []);
Adding a 2nd parameter like, 'options'
or 'dog'
or anything else, removes the PHP error but then also removes the display of all the ACF field data on each post in the custom post type single pages.
We’re trying to understand what we’re doing wrong here as none of the archive pages: 'archive-our_models.php
', 'content-our_models'
or similar files that are used in developing the archive page are at all referencing the controller, as far as we know or can tell.