post__in works but also prints the word Array

Array is how PHP represents an array when it is converted to a string:

echo array( /* anything in here */ ); // output: Array

Fortunately for you, PHP doesn’t really like converting arrays to strings, so it will give an error like this:

PHP Notice: Array to string conversion in /somefile.php on line 345

Usually these PHP notices are silenced by default. To see them, you should enable WordPress debugging mode with WP_DEBUG. Frankly, you should have WP_DEBUG enabled any time you are developing something with WordPress :-).

Once you’ve enabled debugging mode, run your code and check the debug.log. You should see an array to string conversion notice from PHP, which will tell you where this came from.

Like @Sisir, I don’t see any problems with your code. I suspect that the array is being output by a function hooked to one of the actions or filters called by get_the_post_thumbnail(): 'post_thumbnail_size', 'begin_fetch_post_thumbnail_html', 'end_fetch_post_thumbnail_html', and 'post_thumbnail_html'.

Leave a Comment