0

I'm trying to build a site at the moment that includes the different stores and times that albums will release.

I'm not sure how I should structure it with custom taxonomies and custom fields etc. The main problem is that I want each taxonomy to have the same fields but different values for each post.

I'm thinking:

Post = An Album Release Stores = Custom Taxonomy (includes Amazon, Discogs, iTunes, Tidal etc)

Album X might be available at two stores but each would have a different release time and price.

Example

Post - Album X Stores - Amazon (released 12pm, price 9.99), iTunes (released 9am, price 7.99)

Ideally I want to be able to create a post for Album X and have a table/box at the bottom of the edit page which would have a drop down to select first store, then a few customisable fields for that store on that post only. Then another drop down for store 2 and store 3 etc.

I hope I've explained this OK.

What is the best way to structure something like this and what I should use such as plugins etc that can provide this functionality?

  • 2
    What is the question exactly? – Iceable Aug 7 '18 at 14:45
  • What is the best way to structure something like this and what I should use such as plugins etc that can provide this functionality? – lpw Aug 7 '18 at 15:26
  • Please note that questions asking for plugin recommendations are considered off-topic here. – bosco Aug 9 '18 at 1:03
1

I would implement this as such:

Album is a Custom Post Type (CPT). Release date, stores, and store details are post meta-data for the Album CPT.

Meta-data can be structured, so one option would be to store all of an album's store data as an array of associative arrays similar to the following:

// You would build this array from user-entered data collected from a form in a metabox
$album_stores = [
  [
    "name" => "Amazon",
    "url" => "https://amazon.com/album-name",
    "price_usd" => "23.95"
  ],
  [
    "name" => "Google Play",
    "url" => "https://play.google.com/music/album-name",
    "price_usd" => "22.50"
  ]
]

update_post_meta( $post->ID, "album_stores", $album_stores );
update_post_meta( $post->ID, "album_release_date", $release_date );

If you would like to be able to search or sort albums by store, a store custom taxonomy would be convenient, and could automatically be applied when an Album is published or updated based on the presence of the relevant meta-data. Otherwise, search could also be implemented by modifying or creating search queries to query Album CPT meta-data (this would also allow you to search based on store details like price, or some such).

Register a custom meta-box to the Album CPT in order to provide the user interface for editing the store and release date meta-data.

  • Thank you for the suggestion.. Looks like this method should do what I need! – lpw Aug 9 '18 at 14:46
  • The only thing I'm not sure about is that album needs to have a number of different prices (one for each store). So if I had an album meta field called "price" this is only singluar. I basically need a price for each selected (store) taxonomy term. – lpw Aug 9 '18 at 14:53
  • Note that meta-data can store multi-dimensional data, like an associative array. So instead of seperate pieces of meta-data for store and price and url, you could have one key for each store containing all of the data related to that store - or even pack every store and it's associated details into a single meta data entry (which may simplify code elsewhere by allowing you to loop through all the store data in one variable instead of asking WordPress for the data for every store individually). I'll try to expand on this a little later. – bosco Aug 9 '18 at 15:02
  • Great thanks.. Yes I'm not sure I'm explaining well enough? I need for example on a post "Store 1 price", "Store 1 Time", "Store 2 Price", "Store 2 Time" as fields but each store needs to be a selected taxonomy term – lpw Aug 9 '18 at 16:15
  • Yes, I understand. You'll want to store this data as post meta-data separate from the taxonomy terms as it varies from album to album. I've added an example of the data structure I'd use for the store info post meta-data. – bosco Aug 10 '18 at 15:07

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.