Module

Developer
Supported

Google Custom Search

ExpressionEngine 2, ExpressionEngine 3, ExpressionEngine 4

Back to this add-on's main page
View Other Add-ons From Derek Hogue

     

You must be logged in to post.

Errors when returning 0 results - Undefined index: totalResults

General

petenice
petenice

Greetings,

Thank you for this plugin, I’ve relied on it for years, it’s great.

Lately, I’m seeing PHP errors when we do a search that returns zero results.

————————-

A PHP Error was encountered
Severity: Notice

Message: Undefined index: totalResults

Filename: google_custom_search/mod.google_custom_search.php

Line Number: 474

————————-

A PHP Error was encountered
Severity: Warning

Message: Cannot modify header information - headers already sent by (output started at /Users/user/public/system/codeigniter/system/core/Exceptions.php:170)

Filename: core/Common.php

Line Number: 479

————————-

Derek Hogue
# 1
Developer
Derek Hogue

Can you tell me what version of EE and what version of the module you’re running?

petenice
# 2
petenice

Yes, thank you for your quick response.

ExpressionEngine v2.11.1

Google Custom Search 1.2.1

Derek Hogue
# 3
Developer
Derek Hogue

Thanks. And does this happen with every search? Have you tried different keywords?

petenice
# 4
petenice

It happens only when the search returns zero results, I’ve tried it with multiple different keywords

“asdf”
“asdfasdf”
“soybeanz”

petenice
# 5
petenice

You can recreate the error here on the stage site (links sent)

Derek Hogue
# 6
Developer
Derek Hogue

Can you try editing mod.google_custom_search.php as follows?

Where there’s the line (near line 489):

if($json['queries']['request'][0]['totalResults'== 0

Change it to:

if(empty($json['queries']['request'][0]['totalResults']) || $json['queries']['request'][0]['totalResults'== 0
petenice
# 7
petenice

You sir are incredible. That worked! Error gone.

petenice
# 8
petenice

Thank you, Thank you, Thank you, Thank you!

Derek Hogue
# 9
Developer
Derek Hogue

Great, glad that sorted you out!