Support » Plugin: dsIDXpress » PHP Warning: in_array() expects parameter 2 to be array

  • Resolved linux4me2


    I noticed this past week after upgrading to v. 3.3.0 of the dsIDXPress plugin that my error log was filling up with errors like the following:

    PHP Warning: in_array() expects parameter 2 to be array, null given in /home/username/public_html/wp-content/plugins/dsidxpress/widget-idx-guided-search.php on line 109
    PHP Warning: array_map(): Argument #2 should be an array in /home/username/public_html/wp-content/plugins/dsidxpress/widget-idx-guided-search.php on line 109

    I do have the premium version of the IDX Guided Search widget on the site, but try as I might, I haven’t been able to reproduce the warning. I’ve tried doing searches with no parameters, searches with different variations of cities selected, and even tried accessing the file directly, but I haven’t been able to figure out how users/bots are triggering the warning. However, if I wait a while, the error log starts filling up again. It actually got as high as 100 MB at one point, so it can definitely be an issue for users who have limited disk space.

    The problem code is line 109 in /wp-content/plugins/dsidxpress/widget-idx-guided-search.php:

    $selected = in_array(strtolower($city), array_map('strtolower', $values['idx-q-Cities']))?' selected="selected"':'';

    I found a workaround that appears to retain the functioning of the widget but prevents the warnings by testing to be sure that $values['idx-q-Cities'] is an array before using it in the in_array function. To try it, simply replace line 109 of /wp-content/plugins/dsidxpress/widget-idx-guided-search.php with the following:

    if (is_array($values['idx-q-Cities'])) {
      $selected = in_array(strtolower($city), array_map('strtolower', $values['idx-q-Cities']))?' selected="selected"':'';
    } else {
      $selected = '';

    I don’t think it matters, but I’m using WP 5.0.2 on PHP 7.1.

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author LindzConnell



    I had one of our Support Reps check into this. He was not able to reproduce the issue with the information given. To investigate this further, we’re going to need to get a bit more detailed. If you would, please call/email our Support Team directly so they can dig into this more with you.

    Thank you!


    For some reason, I never got the notice that you replied to this, but when I updated to version 3.4.0 of dsIDXpress and my changes were overwritten, the error returned, though with the new version it is on line 107 rather than 109.

    I’ll give Support a call.

    Plugin Author LindzConnell



    Sounds good! Our team will be happy to help.

    I spoke to Tony in Support, and he was unable to reproduce the PHP warning I was getting. We decided I would add some code to the conditional I was using to see if I could get some more info. I ended up using the following on line 107 of /wp-content/plugins/dsidxpress/widget-idx-guided-search.php to output some data to the error log when the warning occurred:

    if (is_array($values['idx-q-Cities'])) {
      $selected = in_array(strtolower(trim($city)), array_map('strtolower', $values['idx-q-Cities']))?' selected="selected"':'';
    } else {
      // Begin debugging code here.
      error_log('idx-q-Cities is not an array with the following variables:' . "\n" . print_r($_REQUEST, true) . "\nIP:" . $_SERVER['REMOTE_ADDR'] . "\n" . $_SERVER['REQUEST_URI'] . "\n" . $_SERVER['HTTP_USER_AGENT']);
      // End debugging code. 
      $selected = '';

    I waited a while, and the Bing bot obliged by triggering the debugging code. It turns out I can reliably reproduce the warning by using a URL like:


    I tried with two cities that are in our MLS area, and both resulted in 547 entries in the error log. One city didn’t return any results, so the 547 isn’t related to the number of results.

    I called Support back and explained what I’d found. Ian told me they would look into it further. I’ll post back when I hear from them.

    Plugin Support dstonyh


    Hello @linux4me2,

    Had some time to look over this, and here’s the issue with the /idx/city/location pages (line ~52):

    $specialSlugs = array(
    	'city' 		=> 'idx-q-Cities',
    	'community' => 'idx-q-Communities',
    	'tract' 	=> 'idx-q-TractIdentifiers',
    	'zip' 		=> 'idx-q-ZipCodes'
    $urlParts = explode('/', $_SERVER['REQUEST_URI']);
    $count = 0;
    foreach($urlParts as $p){
    	if(array_key_exists($p, $specialSlugs) && isset($urlParts[$count + 1])){
    		$values[$specialSlugs[$p]] = $urlParts[$count + 1];

    This piece of code handles the pretty URL pages for /idx/city/, /idx/community/, etc. However, what’s happening is on these pages it’s then setting the $values[] array to a string value.

    The solution is to replace this line (~63):
    $values[$specialSlugs[$p]] = $urlParts[$count + 1];

    With this:
    array_push($values[$specialSlugs[$p]], $urlParts[$count + 1]);

    This will simply push the value to the end of the array, which should be empty.

    The number of warnings (not errors) that you get in your logs has to do with how many values you have in the IDX Guided Search widget fields. So 540+ warnings means that you have that many locations in your City field.


    • This reply was modified 1 year, 4 months ago by dstonyh. Reason: Added line numbers
    • This reply was modified 1 year, 4 months ago by dstonyh. Reason: Added explanation of warnings
    • This reply was modified 1 year, 4 months ago by dstonyh.

    Hi @dstonyh,

    That fix works. I appreciate the explanation of the 540+ warnings. There are indeed 547 cities in the cities list of the Guided Search Widget on the site.

    I hope this fix can be added to the next release of the plugin. Although they are warnings and not errors, they were racking up some impressive error log file sizes and chewing through the disk space this site is allowed on the server.

    Thanks for all your help!

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘PHP Warning: in_array() expects parameter 2 to be array’ is closed to new replies.