Last active
October 6, 2015 11:59
-
-
Save kurozumi/42d10f8eb8dfb99944df to your computer and use it in GitHub Desktop.
【ワードプレス】指定した投稿タイプのカスタムフィールドのキーをすべて取得する関数
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
<?php | |
if(!function_exists('get_meta_keys_from'): | |
function get_meta_keys_from($post_type) | |
{ | |
global $wpdb; | |
$query = <<< __SQL__ | |
SELECT | |
meta_key | |
FROM $wpdb->postmeta | |
JOIN $wpdb->posts | |
ON $wpdb->posts.ID = $wpdb->postmeta.post_id | |
WHERE | |
$wpdb->posts.post_type LIKE '%s' AND | |
$wpdb->postmeta.meta_key NOT LIKE '%s' | |
GROUP BY meta_key | |
ORDER BY meta_key | |
__SQL__; | |
$prepare = $wpdb->prepare($query, array($post_type, '\_%')); | |
return $wpdb->get_col($prepare); | |
} | |
endif; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment