I have created a Custom Post Type called Products.

Now I need a functionality that will allow me to select or check a product as featured.
There can be only one featured product.
When one product is selected the others are deselected automatically.
This featured product will be displayed on homepage.

Question:

What is the best way to store the featured_product_id to identify the one that is featured?

有帮助吗?

解决方案

There is no need to store product setting product wise as there will be only one featured product. You can store the featured_product_id in options table. And whenever a product is featured you just override the record in the options table, that why you can avoid the deselecting hassle of previously selected featured product.

其他提示

I create an options page and then have a list of all products there where I can choose the product to be featured.

许可以下: CC-BY-SA归因
scroll top