0

I'm currently developing a Wordpress website that has a large navigation that lists the 4 most recent posts within a hierarchical taxonomy. I dont have any experience with $wpdb, but it seems like that would be the most efficient way to get results for many taxonomies as opposed using many WP_Query s for each tax... this site also gets a considerable amount of traffic. I am using transients API and caching other things well...

So basically to reiterate, I'm trying to do this:
1) I have 22 terms within a custom taxonomy.

2) I need to select the 4 most recent posts within each term

3) I need the title, the post thumbnail, and the permalink

4) These are all going to be either posts or pages

Any tips or help is hiiiighly appreciated.

thank you

0

This is possible, but there's not a "neat" way to do it. There's a great write-up here:

Display the Most Recent Post in Each Category

but as the author points out, it's a separate query to get the most recent posts for each term. To his great credit, he does deal with caching them, which will help tremendously with the load this would place on your database / server.

  • Hm.. that post would be the extremely resource intensive way to deal with this problem that I know how to do. I feel like there must be a way to use a custom query though that although might be a complex one, would be better than 20 seperate queries. – Cluster Jun 14 '13 at 3:40
  • @Cluster - I agree about the resource intensive part. The other alternative I had considered was to just open a wpdb connection for ALL posts (date descending), iterate through them one at a time, keeping a count of how many per term, until you'd filled up all the terms or gone through all the records. That would be less resource intensive, but still fairly intense. I doubt you'd have much luck with a single query to do this, especially one that could be "automatic" and adjust for any new terms added in the future, etc. – cale_b Jun 14 '13 at 17:24

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.