It's a bit more complicated than that.
For a travel website, I have 3 parent categories: Series, Post Type, and Location.
Each post is assigned to a child category. For example (respectively): EU2014, Picture Gallery, and Rome.
On each post, there is a sidebar. My intention is that this sidebar will contain links to the other related posts. A post is related if it is:
1.) In the same Series child category (such as "EU2014") AND 2.) in the same Location child category (let's say "Rome").
Really what I'm doing here is making it so that way the client can write any number of posts, and a network of links will appear on all of them (in the sidebar).
So, in sum, all posts designated "EU2014" AND "Rome" will be part of a collection.
Then I can format the sidebar nicely based on what Post Type a post in question is (with appropriate icons or whatnot).
My problem is this:
I need pseudo code. I've started working on it, but I'm very concerned that, if I am to iterate through the entire database of posts every time I load a post, simply to write that sidebar, it will be a massive resource drain on the system.
How can I
1.) Identify the child categories of the current post and 2.) get the names and links of each post whose Series and Location child categories match those of the current post in order to write that information to the sidebar of the current post
without creating a black hole of fuckery when the site grows to more than just a few total posts?
This is going to be written in PHP, so if anyone has any interest in helping me figure out more than just pseudo, I'd be thrilled to suss it out with you.