Subject: Critical Bug in td_util.php Line 1196 – Search Functionality Broken

Posted in: Newspaper
Post count: 209

Critical Bug in td_util.php Line 1196 – Search Functionality Broken (Array to String Conversion)

Description:

I’ve encountered a critical bug in the Newspaper theme that completely breaks the WordPress search functionality. The issue is located in /wp-content/plugins/td-composer/legacy/common/td_util.php at line 1196.

Symptoms:

  • Search returns “Critical Error” message
  • Site becomes inaccessible when performing searches
  • Error occurs both on frontend search and AJAX search
  • Debug log shows: PHP Fatal error: Uncaught TypeError: implode(): Argument #2 ($array) must be of type ?array, string given

Root Cause:

Line 1196 in td_util.php contains:

$buffer .= implode(' ', $value);

The function implode() expects $value to be an array, but in some cases (particularly with custom post meta or complex search queries), $value can be a string, causing a fatal TypeError.

Temporary Fix/Workaround:

Replace line 1196 with proper type checking:


// Line 1196 - Fixed version with type checking
if (is_array($value)) {
$buffer .= implode(' ', $value);
} else {
$buffer .= (string)$value;
}

This fix checks if $value is an array before using implode(), and converts it to a string if it’s not an array.

Steps to Reproduce:

  1. Install Newspaper theme with td-composer plugin
  2. Use WordPress search with complex queries or custom post meta
  3. Search function triggers fatal error

Environment:

  • Newspaper Theme (latest version)
  • td-composer plugin (included with theme)
  • PHP 8.0+
  • WordPress 6.x

Request:

Could you please include this fix in the next update of td-composer? This is a critical bug that breaks essential site functionality. The type checking ensures compatibility with all data types that might be passed to this function.

Affected File:
/wp-content/plugins/td-composer/legacy/common/td_util.php – Line 1196

Thank you for your attention to this matter!

  • This topic was modified 9 months by be2name.
Post count: 35449

Hi,
Thank you for the information. I will let our developer know about this and add it to our list for requests.
Thank you!

Post count: 209

Too bad this wasn’t fixed with the latest update 🙁

Post count: 35449

Hi,

This issue is already on our list. Unfortunately, our developers weren’t able to resolve all the bugs that appeared after the theme update to version 12.7.2, and we needed to release 12.7.3 as soon as possible. However, this should be fixed in the upcoming theme update!

Thank you for your understanding.

Post count: 209

Hello tagDiv team,

I have an update regarding the search functionality errors:

Status Update:

  • FIXED: The original implode() error has been resolved in the latest version
  • NEW ISSUE: A critical error has been discovered at a different location

New Error Details:

Error Message: Fatal error: Uncaught Error: Cannot access offset of type array on array in td_util.php on line 1196

Problem Description: The code in td_util.php at line 1196 assumes get_query_var('post_type') always returns a string. However, this function can return an array when multiple post types are being searched. This causes a fatal error when the array is used as an array key.

Current Problematic Code (Line ~1192-1196):

$post_type = get_query_var('post_type'); if ( !empty($post_type) && $post_type !== 'post' ) { $td_cpt = td_util::get_option('td_cpt'); if ( !empty( $td_cpt[$post_type]['search_tpl'] ) ) { // ← FATAL ERROR HERE $cpt_search_template_id = $td_cpt[$post_type]['search_tpl']; } }

Proposed Fix:

$post_type = get_query_var('post_type');

// Fix: get_query_var('post_type') can return an array, handle both cases if ( is_array($post_type) ) { $post_type = !empty($post_type) ? $post_type[0] : ''; }

if ( !empty($post_type) && $post_type !== 'post' ) { $td_cpt = td_util::get_option('td_cpt'); if ( !empty( $td_cpt[$post_type]['search_tpl'] ) ) { $cpt_search_template_id = $td_cpt[$post_type]['search_tpl']; } }

Environment:

  • Newspaper Theme (latest version)
  • td-composer plugin (included with theme)
  • PHP 8.0+
  • WordPress 6.x

Impact: Search functionality is completely broken. This is a critical bug that prevents users from using the search feature on the site.

Request: Could you please include this fix in the next update of td-composer? This is a critical bug that breaks essential site functionality. The array type checking ensures compatibility with all scenarios where get_query_var('post_type') might return different data types.

Affected File: /wp-content/plugins/td-composer/legacy/common/td_util.php – Line 1196

Thank you for your attention to this matter!

Best regards

  • This reply was modified 9 months by be2name.
Post count: 209

Sorry, file is in
/wp-content/plugins/td-composer/legacy/common/wp_booster/

Post count: 35449

Thank you for the update!

Post count: 29

@be2name your proposed fix works ok!
Thank you

Post count: 17

Hi @calin, Any info about the release date of the fix in the official update of the theme?

Post count: 35449

Hi,

A theme update containing the fix will be released, but unfortunately, I’m unable to provide an estimated release date at this time. My apologies!

Thank you!

Post count: 11

Works so fine
Tks

Post count: 29

I do not think it is fixed at 12.7.3, still using the patch from this thread

Post count: 35449

Hi depatech,
If you have the latest version and you face a critical error when using the search, it will be need to replace the current theme plugin tagDiv Composer with the one from here – https://cdn.tagdiv.com/wp-content/uploads/2025/11/td-composerfix.zip
Thank you!

Viewing 13 posts - 1 through 13 (of 13 total)
You must be logged in to reply to this topic.