madebyraygun / trending-posts

Trending Posts for Craft CMS 3 tracks pageviews over time and orders posts by popularity on the front-end.
MIT License
6 stars 3 forks source link

Error array_intersect(): Expected parameter 2 to be an array, string given #13

Open dgtlcrftrs opened 4 years ago

dgtlcrftrs commented 4 years ago

https://github.com/madebyraygun/trending-posts/blob/bbdc7c9dd929d1386de30590a663f1a01f0e8d75/src/TrendingPosts.php#L102

This line is causing an error due to the fact that it is expecting $getSection to be an array. However I am only tracking one section and my query is for that section so the returned variable ($getSection) is a string. I have added a conditional above that line to check if it's an array and if not, to turn it into one which resolved my issue.

$getSection = is_array($getSection) ? $getSection : array($getSection);

daltonrooney commented 4 years ago

Why not just wrap the number you pass to the setting in brackets? I.e:

$sectionID = 1;
return [
  'trackSection' => [$sectionId]
];
dgtlcrftrs commented 4 years ago
return [
    'trackDays' => 91, //default is 7 days
    'trackSection' => [2], //limit tracking to specific sections
    'visitorTimeout' => 30 //default is 15 minutes
];

It is If thats what you meant. This is clearly a bug of some sort that has only occurred since updating to craft 3.4.28.1.