Skip Navigation

[Resuelto] How to find unique values of a custom field

This support ticket is created hace 5 años, 5 meses. 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.

Hoy no hay técnicos de soporte disponibles en el foro Juego de herramientas. Siéntase libre de enviar sus tiques y les daremos trámite tan pronto como estemos disponibles en línea. Gracias por su comprensión.

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)

Etiquetado: 

Este tema contiene 1 respuesta, tiene 2 mensajes.

Última actualización por Nigel hace 5 años, 5 meses.

Asistido por: Nigel.

Autor
Mensajes
#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

Idiomas: Inglés (English ) Español (Español )

Zona horaria: 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.

enlace oculto

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'.