I\'ve written some code which automatically creates some posts and adds a tag to them. I can see the tags in the \'All posts\' admin panel and I can click on the posts \'Ta
In your code, try:
$query=new WP_Query(array('posts_per_page=5', 'tag' => $brand_name));
instead of:
$query=new WP_Query(array('posts_per_page=5', array('tag' => array($brand_name))));
For further details, see https://codex.wordpress.org/Class_Reference/WP_Query#Tag_Parameters (and as mentioned on a recent duplicate post).
Note: $brand_name could be an array of strings, or comma separated values, etc., and the above code should work.
Alternatively, try:
$myPosts = get_posts(array('tag' => $brand_name));
See https://codex.wordpress.org/Template_Tags/get_posts