I'm somewhat new to Wordpress customization and need some help navigating the "Wordpress way" of doing things!

For this example, let's say I run a subscription box service where users can pick 3 products they want to receive every month from a list of 10 items.

If I were doing this outside of Wordpress, I might have a Users table, a items table, and a months table. The user table would contain standard user information. The items table would contain information about the item -- name, description, image, etc. The Months table would contain information about the Month. This may sound weird (why not just have a date field somewhere!?) but there is information about the month, such as what day of the month the items will ship, if it's a "special" month -- e.g. we might want to market December as "Holiday Month" rather than "December".

Then, each month the user could login and see what products are available each month because I've created a "month_products" table that contains an item id and month id for each record to show what products are available for that month.

When the user selects their product, it then stores it in a "user_product_selections" table that contains the user id, item id, and month id.

This is all pretty standard stuff in web app land, but I have no idea how to duplicate this "natively" in Wordpress.

I obviously already have the users table, which is great. I can easily create a custom post type for items that works great. I could also create another custom post type for the "Months" data.

Past that, I'm confused about how this should interact and how to create the functionality of the "month_products" and "user_product_selections" tables in Wordpress.

Any help here would be greatly appreciated! I know I can always just veer off on my own and start creating my own tables in the Wordpress database, but I want to do things the right way for Wordpress.

  • The database structure that do use a table correspond to a custom post type. Then for the relation beetween "month" and "product" product 3 CPT : "mounth", "product" and "month_products". You confirm that you need a "many to many" relation, i.e. a product can be associated to many mounths and a mount can be associated to many products ? – mmm Feb 1 '18 at 13:31
  • That's correct on the many-to-many relationships. – ssharp_wp Feb 1 '18 at 13:51
  • ok. then in the CPT "month_products" you will set meta values "mounth_id" and "product_id" (codex.wordpress.org/Custom_Fields). For the relation describing the user selection, are think that the relation is between "user" and "month_products" otherwise a relation can exist with a product that doesn't exist for the given month (if you don't use PHP to verify the coherence) – mmm Feb 1 '18 at 13:56

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.