The immediate answer to your question is that you can just add a category ID to the query_posts()
call, e.g.:
query_posts('orderby=rand&showposts=1&post_type=gallery&cat=10');
Slightly longer answer is that it’s not a good idea to use query_posts
in themes and plugins. More info in the docs here: https://developer.wordpress.org/reference/functions/query_posts/
You might want to take the opportunity to change the code to use get_posts
or WP_Query
, you just need to put the arguments in an array instead of a query string.