Title: &#8220;in_array() expects parameter 2 to be array, string given&#8221;
Last modified: October 28, 2021

---

# “in_array() expects parameter 2 to be array, string given”

 *  Resolved [Bowo](https://wordpress.org/support/users/qriouslad/)
 * (@qriouslad)
 * [4 years, 7 months ago](https://wordpress.org/support/topic/in_array-expects-parameter-2-to-be-array-string-given-3/)
 * Hi,
 * My debug log is showing this error:
 * “in_array() expects parameter 2 to be array, string given”
 * …which happens during execution of /includes/youtube-api.php at:
 *     ```
       // Store data in transients
       if ( $transient_expiration > 0 ) {            
           set_transient( $transient_key, $data, $transient_expiration );
   
           // Get the current list of transients
           $transient_keys = get_option( 'ayg_transient_keys', array() );
   
           // Append our new one
           if ( ! in_array( $transient_key, $transient_keys ) ) {
               $transient_keys[] = $transient_key;
           }
   
           // Save it to the DB
           update_option( 'ayg_transient_keys', $transient_keys );
       }
       ```
   
 * Is it a problem with the API key?… or something else?
 * Thank you.

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

 *  Thread Starter [Bowo](https://wordpress.org/support/users/qriouslad/)
 * (@qriouslad)
 * [4 years, 7 months ago](https://wordpress.org/support/topic/in_array-expects-parameter-2-to-be-array-string-given-3/#post-15015430)
 * If I check in the wp_options table, ayg_transient_keys key has no value in it.
 *  Thread Starter [Bowo](https://wordpress.org/support/users/qriouslad/)
 * (@qriouslad)
 * [4 years, 7 months ago](https://wordpress.org/support/topic/in_array-expects-parameter-2-to-be-array-string-given-3/#post-15015443)
 * Additionally, before checking the wp_options table, I cleared the cache via plugin
   setting… which may explain the empty value for the ayg_transient_keys key?
 *  Plugin Contributor [wpvideogallery](https://wordpress.org/support/users/wpvideogallery/)
 * (@wpvideogallery)
 * [4 years, 7 months ago](https://wordpress.org/support/topic/in_array-expects-parameter-2-to-be-array-string-given-3/#post-15017365)
 * [@qriouslad](https://wordpress.org/support/users/qriouslad/),
 * Thanks for bringing this issue to us.
 * I have taken a note of this now and I promise that our next version would have
   this issue addressed.
 * Yes, the issue occurs when the cache is cleared and the “ayg_transient_keys” 
   option goes empty.
 * As an immediate solution, kindly edit open the /includes/youtube-api.php file,
 * Find the line below,
    `$transient_keys = get_option( 'ayg_transient_keys', array());`
 * Change it as,
 *     ```
       $transient_keys = get_option( 'ayg_transient_keys', array() );
       if ( ! is_array( $transient_keys ) ) {
           $transient_keys = (array) $transient_keys;
       }
       ```
   
 * Save the changes and check now.
 * Hope this solved your issue!
    -  This reply was modified 4 years, 7 months ago by [wpvideogallery](https://wordpress.org/support/users/wpvideogallery/).
    -  This reply was modified 4 years, 7 months ago by [wpvideogallery](https://wordpress.org/support/users/wpvideogallery/).
 *  Thread Starter [Bowo](https://wordpress.org/support/users/qriouslad/)
 * (@qriouslad)
 * [4 years, 7 months ago](https://wordpress.org/support/topic/in_array-expects-parameter-2-to-be-array-string-given-3/#post-15017427)
 * Thank you! Yes, that solved it. Have a great day!

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

The topic ‘“in_array() expects parameter 2 to be array, string given”’ is closed
to new replies.

 * ![](https://ps.w.org/automatic-youtube-gallery/assets/icon-128x128.png?rev=1992335)
 * [Automatic YouTube Gallery](https://wordpress.org/plugins/automatic-youtube-gallery/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/automatic-youtube-gallery/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/automatic-youtube-gallery/)
 * [Active Topics](https://wordpress.org/support/plugin/automatic-youtube-gallery/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/automatic-youtube-gallery/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/automatic-youtube-gallery/reviews/)

 * 4 replies
 * 2 participants
 * Last reply from: [Bowo](https://wordpress.org/support/users/qriouslad/)
 * Last activity: [4 years, 7 months ago](https://wordpress.org/support/topic/in_array-expects-parameter-2-to-be-array-string-given-3/#post-15017427)
 * Status: resolved