A
A
Alexey selftrips.ru2020-06-20 06:47:29
SQL
Alexey selftrips.ru, 2020-06-20 06:47:29

How to get a list of unique field values?

There is a table wp_postmeta
with fields
meta_id(Primary)
post_id
meta_key
meta_value

How to get a list of unique values ​​of the meta_key field ?
Thanks

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
serg1764, 2020-06-20
@serg1764

Greetings.
From the WP environment.
global $wpdb;
$result = $wpdb->get_results( "SELECT meta_value FROM table WHERE meta_key=`field name` AND post_id='post number';" );
It is better to test the request in phpMyAdmin and then insert it.
Dale print the result of the query using print_r($result);
And then write a specific appeal to the element.

K
Konstantin Tsvetkov, 2020-06-20
@tsklab

SELECT DISTINCT meta_key FROM wp_postmeta

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question