Last active
June 6, 2024 08:42
-
-
Save hazratbilal0079/7ac053649ce025b59273e3d5afcf3f85 to your computer and use it in GitHub Desktop.
Retrieve Distinct meta field values from Custom Post Type in WordPress
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT DISTINCT pm.meta_value AS your_meta_field_name | |
FROM wpd8_posts AS p | |
INNER JOIN wpd8_postmeta AS pm ON p.ID = pm.post_id | |
WHERE p.post_type = 'your_post_type_name' AND pm.meta_key = 'your_meta_field_name'; | |
Example | |
SELECT DISTINCT pm.meta_value AS property_name | |
FROM wpd8_posts AS p | |
INNER JOIN wpd8_postmeta AS pm ON p.ID = pm.post_id | |
WHERE p.post_type = 'owner-data' AND pm.meta_key = 'property-name'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment