Custom post type history

Here’s what I have right now:

Custom Post Type for a list of Draft Beers Available.
These Drafts are updated frequently.

I’ve set it up so that each draft beer is paired to a draft line number.
ex. 1 – coors, 2 – Bud, 3 – Labatte, etc.

Right now, you can easily update what draft beer is on which draft line by updating the existing custom post(draft).
ex. 10 lines with 10 posts and user updates each one.

I have it set up to Time Stamp when it was updated.

Here’s what I want it to do:

I want each draft line(number) to have it’s own history.
Basically, each draft line would be it’s own CPT in a way in that it has a collection of posts(drafts) but only shows the most recent unless searched or viewed.

But do I have to create a custom post type for each draft line?
I’m hesitant because there are about 45 draft lines.

Is there a better way to achieve this?
Would a child-term or child category achieve this?

Here’s what I know:

1 Answer
1

I would probably go with a custom post type ( draught – the golden honey from the gods ) as you already have.

I would then create two taxonomies, keg ( which can be a hierarchical taxonomy ) and line ( which can be a non-hierarchical taxonomy )with their respective terms.

Example :

  • keg

    • coors
    • bud
    • labatte
  • line

    • one
    • two
    • three

The reason for keg being hierarchical is that you can later have child terms under your parent terms which makes it easier to extend

Each time a new post is published, you can assign one term from each taxonomy to it. The advantage here is, you are looking for a system where you can keep records of previous pairings etc. You will not have this if you simply keep on updating the same post. Yes, you can work with revisions, but that is really not the way to go here

So what you should do is, create a new post everytime something changes in your line up and assign the appropriate terms to that specific post.

The only issue is going to be how you are going to display them on your home/front page ( I would opt for a static front page here). In my opinion, you will need to loop over each term in the line taxonomy and get the latest post from each term using WP_Query or get_posts. You would may be need to sort the results for them to be in numerical line order and you will need transients to store your results as it can become an expensive query to run

Here are some posts you might find useful in connection with the above

  • Custom sort order with get_terms -> This post uses get_users but you should be able to use this on get terms. I do thing it will be best first to create your tems in numerical order, one first and ten last, then you can simply use the build in sort by ID to sort your terms

  • Using transients -> In this post I have explained well with code how to setup and use transients to save on db calls and time.

I hope the above info makes sense

Leave a Comment