Illegal offset type in isset or empty in post_type_archive.php

[ad_1]

We recently upgraded a client to PHP 8.1 and was receiving this error:

PHP Fatal error:  Uncaught TypeError: Illegal offset type in isset or empty in /[deleted]/wordpress/wp-content/plugins/query-wrangler/includes/overrides/post_type_archive.php:110

After doing some debugging it appears that the $post_type being received was an array consisting of [ ‘podcast’, ‘post’ ].

Line 110 contains:

if ( isset( $post_type_archives[ $post_type ] ) && $qw_query = qw_get_query( (int) $post_type_archives[ $post_type ] ) ) {

Which throws the error.

Adding this fixes it:

if ( !is_array( $post_type ) && isset( $post_type_archives[ $post_type ] ) && $qw_query = qw_get_query( (int) $post_type_archives[ $post_type ] ) ) {

Is this the correct approach or did the original designer/developer for the site misuse the post_type tags and should be sending a string rather than array?

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer