Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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?

share|improve this question
add comment

1 Answer

up vote 4 down vote accepted

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.

share|improve this answer
    
actually, the pre_get_posts action is the best option :) query_posts and WP_Query are just more convenient –  Kegan Quimby 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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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