fixed query for attachments, also using a new method available in WordPress since v3.6 with backwards compatibility