Support » Plugin: Relevanssi - A Better Search » mb_strtoupper() expects parameter 1 to be string, array given

  • Hi,

    I use relevanssi on a custom page template with a custom wp_query and when the results are more than 1, I get the following warning:
    Warning : mb_strtoupper() expects parameter 1 to be string, array given in
    /var/www/mysites/mysite/wp-content/plugins/relevanssi/lib/common.php on line 31

    I also use PHP 7.2, if that matters.

    Apparently, as the warning states, there is a variable that is expected to be a string but it is an array instead. So, I made it go away by wrapping the entire contents of the function on an if(is_string($str1)) {}, since it made sense to do so.

    The warning is gone and the search works as expected, so I was wondering if this should be included on the plugin’s code or there is a better way to deal with the issue.

    Thanks

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

    (@msaari)

    You’re fixing the symptoms, when you should be fixing the cause. Something is wrong elsewhere if a string comparison function is getting an array.

    The only place that function is called is in sorting, when comparing string values. Which sort ordering are you using for your results?

    Thanks for the quick response.

    I am ordering a list of people based on their surname, which is a custom field (ACF). Here is the full list of arguments:

    $args          = [
    	'post_type'      => 'consultant',
    	'posts_per_page' => 22,
    	'meta_key'       => 'surname',
    	'orderby'        => 'meta_value',
    	'order'          => 'ASC',
    	's'              => $keyword,
    ];

    Do you think that I should handle ordering in a different way?

    Plugin Author Mikko Saari

    (@msaari)

    Actually, this is likely a bug I’ve already fixed, but the fix isn’t released yet. If you replace the lib/sorting.php file with the new version from Github (https://github.com/msaari/relevanssi/blob/master/lib/sorting.php) I think that might fix this.

    I tried replacing the sorting.php but I got the following fatal error:

    Fatal error: Uncaught ArgumentCountError: Too few arguments to function relevanssi_object_sort(), 2 passed in /var/www/php/mysite.com/wp-content/plugins/relevanssi/lib/search.php on line 1113 and exactly 3 expected in /var/www/php/mysite.com/wp-content/plugins/relevanssi/lib/sorting.php:323 Stack trace: #0 /var/www/php/mysite.com/wp-content/plugins/relevanssi/lib/search.php(1113): relevanssi_object_sort(Array, Array) #1 /var/www/php/mysite.com/wp-content/plugins/relevanssi/lib/search.php(1693): relevanssi_search(Array) #2 /var/www/php/mysite.com/wp-content/themes/mysite/page-templates/ajax-consultants.php(23): relevanssi_do_query(Object(WP_Query)) #3 /var/www/php/mysite.com/wp-includes/template-loader.php(74): include('/mnt/c/Users/sa...') #4 /var/www/php/mysite.com/wp-blog-header.php(19): require_once('/var/www/php/qs...') #5 /var/www/php/mysite.com/index.php(17): require('/var/www/php/qs...') #6 { in /var/www/php/mysite.com/wp-content/plugins/relevanssi/lib/sorting.php on line 323

    For the record, the full query is this:

    $keyword       = filter_input( INPUT_GET, 'keyword', FILTER_SANITIZE_STRING );
    $args          = [
    	'post_type'      => 'consultant',
    	'posts_per_page' => 22,
    	'meta_key'       => 'surname',
    	'orderby'        => 'meta_value',
    	'order'          => 'ASC',
    	's'              => $keyword,
    ];
    
    $consultants   = new WP_Query( $args );
    if ( $keyword ) {
    	relevanssi_do_query( $consultants );
    }
    Plugin Author Mikko Saari

    (@msaari)

    Oops, sorry, you need to also grab the updated search.php from the Github repo.

    https://github.com/msaari/relevanssi/blob/master/lib/search.php

    Plugin Author Mikko Saari

    (@msaari)

    The meta query sorting had this exact issue of arrays appearing where strings are expected, and the update will fix this by flattening the arrays.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘mb_strtoupper() expects parameter 1 to be string, array given’ is closed to new replies.