On my website I allow people to upload image galleries. When they click an image there is a next and previous button at the bottom so they can easily scroll back and forth through the images.
I am getting the below error in my log located at /opt/cpanel/ea-php72/root/usr/var/log/php-fpm/
NOTICE: PHP message: PHP Warning: count(): Parameter must be an array or an object that implements Countable in . . . on line 12
It is talking about the line below in my code:
$max = count($photos);
Below is the other code that comes with that line:
$photos = get_field('gallery');
$max = count($photos); <------- error line here -------->
$current = (isset($_GET['image'])) ? intval($_GET['image']) : false;
if ($current !== false) {
if ($current > $max) $current = $max;
if ($current < 1) $current = 1;
}
$next = (($current + 1) < $max) ? ($current + 1) : $max;
$prev = (($current - 1) > 1) ? ($current - 1) : 1;
?>
Basically this code uses get_field('gallery') to get the total amount of photos in the gallery and the number is assigned to variable max.
The rest of the code is how the next and previous buttons work.
I do not know what is wrong. Can somebody help with this?
var_dump($photos);before yourcount($photos);to see what the variable actually contains. It's obviously not of any countable type. Also,get_field()is most commonly used with the plugin "Advanced Custom Fields".