I have a custom page template that pulls in media files via advanced custom fields, as well as query posts. Now, the client wants there to be three sections by default... each one populating with the appropriate images based on another advanced custom field for an image category (which I created).

Normally, I would just query_posts three times. Undoubtedly, this is a hack. Normally, it doesn't cause speed issues, however this site has roughly 50k images, and I'm afraid it will cause the load times to significantly decrease.

Is there a better way to do this way to do this? Maybe pull in all images and then sort them based on the category?


It's not a hack, this is what databases are designed for- querying large quantities of data. If you're concerned about load, you should employ caching on data that doesn't change frequently.

That said, you should not be using query_posts to create additional queries. Really, you shouldn't be using query_posts at all. Create additional queries via WP_Query.

  • actually, the pre_get_posts action is the best option :) query_posts and WP_Query are just more convenient Nov 21 '12 at 19:31
  • @KeganQuimby pre_get_posts is typically for altering just the main query, WP_Query is for additional loops. query_posts just calls WP_Query itself, but it overwrites global variables and produces unpredictable results with things like conditional tags and should be avoided entirely.
    – Milo
    Nov 21 '12 at 19:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.