Skip Navigation

[Gelöst] How to find unique values of a custom field

This support ticket is created vor 4 Jahre, 9 Monate. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+00:00)

This topic contains 1 Antwort, has 2 Stimmen.

Last updated by Nigel vor 4 Jahre, 9 Monate.

Assisted by: Nigel.

Author
Artikel
#1265291

Hi,

I have a custom post with a custom field country. I have like 13000 fields in which I want to find the distinct values. What query should I create for the same?

#1265399

Nigel
Supporter

Languages: Englisch (English ) Spanisch (Español )

Timezone: Europe/London (GMT+00:00)

You want to find out what all of the unique values for some custom field are?

You can't readily do that with WordPress using existing functions and it's not something Toolset can do for you either.

Do you just need to do this one time so you can see what unique values have currently been stored, or is it something you will need to do often?

You need to directly query the database with MySQL for this.

If you are doing it one time only you could use phpMyAdmin or similar to run such a query.

Or if you need to do it programmatically then you can make use of the $wpdb Class that WordPress makes available for interacting directly with the database.

Here are details of that Class: https://codex.wordpress.org/Class_Reference/wpdb

You'll want to create a MySQL query that uses DISTINCT to get unique values for some post meta key.

hidden link

Here is an answer on Stack Overflow that is doing something similar to what you describe: https://stackoverflow.com/a/20293486/1180189

If you are not able to modify that according to your needs you will need to contract a developer to do it for you. They need to know WordPress, but the only thing they need to know about Toolset is that if this custom field is a Types field then it is stored in wp_postmeta with a prefix of 'wpcf-', e.g. 'wpcf-my-custom-field'.

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.