如何在WordPress中搜索我的数据库以获取自定义字段的所有选项?

如何在WordPress中搜索我的数据库以获取自定义字段的所有选项?

问题描述:

I'm in a custom taxonomy page and I need to display all the options of a particular custom field called "Region". I tried doing a database query for all the possible values, however because multiple regions are selectable in the custom field, the resulted values are the many different combinations of regions (such as "Asia, Africa, Europe" as one, "Central America, North America" as another and "Europe, Central America", etc etc.)

I want to retrieve just them just singularly, ("Asia" as one, "Europe" as another, etc. etc.) How would I go about doing this?

我在自定义分类页面中,我需要显示一个名为“Region”的特定自定义字段的所有选项 ”。 我尝试对所有可能的值进行数据库查询,但是因为在自定义字段中可以选择多个区域,所以结果值是区域的许多不同组合(例如“亚洲,非洲,欧洲”作为一个,“中美洲, 北美“作为另一个和”欧洲,中美洲“等等。) p>

我想只是单独检索它们,(”亚洲“为一个,”欧洲“为另一个, 等等。)我将如何做到这一点? p> div>

You can use some basic coding approach of php.

Approach:

Use the explode() function of php and set the values in an array for each meta value with a key 'coffee_region' (adding each meta value in the a single array. Make sure you are adding elements not overwriting the previous values of meta in array).

Then use array_unique() function to get rid of the repetitive countries from the array.

And when you print that array you will be having a listing of unique country names from the meta fields