I am writing a Wordpress plugin to store product data that is pulled from the Amazon Affiliates API. My goal is to have an admin page where I can add new products and view/edit/remove existing products.

Essentially I will assign each product a custom slug such as "amazon-miter-saw-blade", then I can use a shortcode such as [wp_product id="amazon-miter-saw-blade"]. This will output something along the lines of

14 Inch Miter Saw Blade - $14.99

For each custom shortcode slug I want to store a product name, price and ID. The name and ID will remain static and the price will be updated every hour on a scheduled cron. As there will potentially be hundreds of products, what are the common options for storing such data? So far I have found that I can create a custom database table, use add_option or transients. Transients would be fine for the price but since the rest is static, would a custom database table or options be better suited?

  • Why just not use the metadata table? Jul 18 '17 at 7:53
  • That would pretty much require a custom post type though to act as the parent object correct? I guess that is probably the best option, just thought there may be a more minimal implementation possible. Jul 18 '17 at 8:02
  • Yes. I would create a new CPT called let's say "Products" and then save all additional information as a metadata. Jul 18 '17 at 8:24

The canonical solution for this kind of problems is to use a custom post type and "get" with zero effort admin framework and caching when object caching is used. Any attribute that is needed can be stored as a meta.

Depending on what are your specific needs are, you can register such a post type as private and then it will be displayed on the front end only when your shortcode is used.

  • I had not considered that approach since it is no more than just a link that will be inserted into an existing post, composed of the data. It almost seems like overkill to create an entire post type to store 4 values per entry. Wouldn't I run into the issue of WP treating these as actual posts, such as adding them to my Sitemap/etc. by default? Jul 18 '17 at 7:56
  • not if you set it as private, at least not with good SEO plugins. The size here do not matter that much, the effort to create administration screens, handle the DB writes and reads, and implement caching is just a worthless waste of time unless you need super optimization. Now if you do not need admin, it might be too much, but sounds like you need one. Jul 18 '17 at 8: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.