Title: Array to string error when using dynamic search variable
Last modified: December 16, 2023

---

# Array to string error when using dynamic search variable

 *  [Andrej Srna](https://wordpress.org/support/users/reesher/)
 * (@reesher)
 * [2 years, 5 months ago](https://wordpress.org/support/topic/array-to-string-error-when-using-dynamic-search-variable/)
 *     ```wp-block-code
       <?php
   
       $product_id = get_the_ID(); // Replace with your product ID$product_post = get_post($product_id);$post_title = $product_post->post_title;
   
       if (is_array($post_title)) {$post_title = implode(' ', $post_title); // Convert array to string}
   
       $post_title = trim(sanitize_text_field($post_title));
   
       $args = array('s' => $post_title,'post_type' => 'post','posts_per_page' => 4,'relevanssi' => true,
   
       );
       ```
   
 * This is my current query I run relevanssi with, however I have error (image)
 * I made sure that the title is not an array as you can see, however when i set
   static word instead of variable
 * eg:
 * ‘s’ => ‘keyword’
 * this works correctly and no error shows.
 * Where could be the issue? I’m missing something?
 * I also tried using relevassi do query function, same result
 * ![](https://i0.wp.com/fitdoplnky.sk/wp-content/uploads/2023/12/Snimka-obrazovky-
   2023-12-16-o-23.26.54.png?ssl=1)

Viewing 1 replies (of 1 total)

 *  Plugin Author [Mikko Saari](https://wordpress.org/support/users/msaari/)
 * (@msaari)
 * [2 years, 5 months ago](https://wordpress.org/support/topic/array-to-string-error-when-using-dynamic-search-variable/#post-17283304)
 * Which version of WP are you using? I looked at what’s on line 4551 of `class-
   wp-query.php`, and at least in the current version, there’s the `is_single()`
   function, which has nothing to do with the search. It doesn’t handle the `s` 
   parameter, so the error is not coming from that. It’s something else.
 * What values of `s` cause this error? The same value should still cause this error
   even when entered as a static value. It may be related to what results the search
   returns.

Viewing 1 replies (of 1 total)

The topic ‘Array to string error when using dynamic search variable’ is closed to
new replies.

 * ![](https://ps.w.org/relevanssi/assets/icon-256x256.png?rev=3529670)
 * [Relevanssi - A Better Search](https://wordpress.org/plugins/relevanssi/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/relevanssi/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/relevanssi/)
 * [Active Topics](https://wordpress.org/support/plugin/relevanssi/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/relevanssi/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/relevanssi/reviews/)

 * 1 reply
 * 2 participants
 * Last reply from: [Mikko Saari](https://wordpress.org/support/users/msaari/)
 * Last activity: [2 years, 5 months ago](https://wordpress.org/support/topic/array-to-string-error-when-using-dynamic-search-variable/#post-17283304)
 * Status: not resolved