Можно вполне использовать foreach, подробнее см. тут: https://stefanledin.se/how-to-use-a-foreach-loop-with-wp_query/