Created
July 6, 2019 11:08
-
-
Save maheshwaghmare/84fa96b952eadfd56d25c5d2852cd70f to your computer and use it in GitHub Desktop.
Get all post meta keys from the WordPress with SQL query.
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( 'prefix_get_all_post_meta_keys' ) ) : | |
/** | |
* Get all meta keys. | |
* | |
* @return mixed Array of the meta keys. | |
*/ | |
function prefix_get_all_post_meta_keys() { | |
global $wpdb; | |
$sql = "SELECT DISTINCT meta_key | |
FROM $wpdb->postmeta | |
WHERE meta_key NOT BETWEEN '_' AND '_z' | |
HAVING meta_key NOT LIKE %s | |
ORDER BY meta_key"; | |
$keys = $wpdb->get_col( $wpdb->prepare( $sql, $wpdb->esc_like( '_' ) . '%' ) ); | |
return $keys; | |
} | |
endif; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment