0

I'm working on a blog that has around 8.000 posts and 50 categories.

The task I'm working on is to list all categories and for each category to show the latest post with a certain custom field value.

My current approach is to get all the categories, loop through them and for each one do a wp_query to find the latest post.

Is there a more efficient way to do this, one that doesn't involve running 50 queries on the page?

  • 3
    I don't have the time to write up the code at the moment, but a hint off the top of my head would be to do it on the admin side when a new post is published (or deleted), save all of your rendered posts data in an option, then you can just load that single option on the front end. – Milo Nov 20 '13 at 23:02
  • Thank you @Milo, I haven't thought of that. If you'll write this comment as an answer I'd be happy to accept it. – Andreyu Nov 21 '13 at 23:18

Your Answer

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

Browse other questions tagged or ask your own question.