• Resolved leedxw

    (@leedxw)


    On search pages, many warnings will be generated regarding “Array to string”

    Array to string conversion in /var/www/html/wp-content/plugins/wpsso/lib/opengraph.php on line 752

    opengraph.php:752:

                        $opt_key    = 'og_type_for_' . $opt_suffix;

    If I look at the value of opt_suffix on a search page, it is an array

    ["post","page","event","resource","internal_news","customer_news"]

    (this was 18.19.5)

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author JS Morisset

    (@jsmoriss)

    Thanks for reporting the issue. The get_og_type_id_for() method is only called from a few places, and all with fixed or known strings. For example, a search page calls his method with the ‘search_page’ fixed string:

    https://github.com/surniaulula/wpsso/blob/main/lib/opengraph.php#L237

    Could a theme or another plugin on your site be calling this method?

    js.

    Thread Starter leedxw

    (@leedxw)

    Uncaught ErrorException: Array to string conversion in /var/www/html/wp-content/plugins/wpsso/lib/opengraph.php on line 752 in /var/www/html/wp-content/themes/cognus/functions.php:216

    Stack trace:
    #0 /var/www/html/wp-content/plugins/wpsso/lib/opengraph.php(752): errHandle()
    #1 /var/www/html/wp-content/plugins/wpsso/lib/opengraph.php(206): WpssoOpenGraph->get_og_type_id_for()
    #2 /var/www/html/wp-content/plugins/wpsso/lib/opengraph.php(87): WpssoOpenGraph->get_mod_og_type()
    #3 /var/www/html/wp-content/plugins/wpsso/lib/opengraph-ns.php(84): WpssoOpenGraph->get_mod_og_type_id()
    #4 /var/www/html/wp-includes/class-wp-hook.php(326): WpssoOpenGraphNS->filter_html_attributes()
    #5 /var/www/html/wp-includes/plugin.php(205): WP_Hook->apply_filters()
    #6 /var/www/html/wp-includes/general-template.php(4531): apply_filters()
    #7 /var/www/html/wp-includes/general-template.php(4546): get_language_attributes()
    #8 /var/www/html/wp-content/themes/cognus/header.php(14): language_attributes()
    #9 /var/www/html/wp-includes/template.php(810): require_once('...')
    #10 /var/www/html/wp-includes/template.php(745): load_template()
    #11 /var/www/html/wp-includes/general-template.php(48): locate_template()
    #12 /var/www/html/wp-content/themes/example/search.php(10): get_header()
    #13 /var/www/html/wp-includes/template-loader.php(106): include('...')
    #14 /var/www/html/wp-blog-header.php(19): require_once('...')
    #15 /var/www/html/index.php(17): require('...')
    Plugin Author JS Morisset

    (@jsmoriss)

    Tracing these function calls, it appears that your search page is a post object and the WordPress get_post_type() function for that post object in the WP Query is returning an array. get_post_type() should return a string or false, not an array (see https://developer.wordpress.org/reference/functions/get_post_type/). Search results from WordPress should not be a post object, and the post type returned by WordPress should not be an array.

    I’ll add some sanity checks in the next version to handle this error, but this won’t fix the underlying issue which is the result of an incorrect WP query object for your search page. If your search page template is provided by your theme (it should be), then I’d suggest trying a different theme to see if the issue persists (it shouldn’t). If the issue goes away, you know that using a post object for the search page and returning an array for the post object type problem is coming from your theme.

    js.

    Plugin Author JS Morisset

    (@jsmoriss)

    FYI, I’ve added an error notice in WPSSO Core v18.20.1-dev.5 if get_post_type() returns an array.

    You can download the current dev version here: https://wordpress.org/plugins/wpsso/advanced/

    js.

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘PHP warnings about “Array to string conversion” on search page’ is closed to new replies.