Skip to content

Instantly share code, notes, and snippets.

@lgedeon
Created August 15, 2017 01:01
Show Gist options
  • Save lgedeon/8b3fe5d4090afd9f502fb30a82026f87 to your computer and use it in GitHub Desktop.
Save lgedeon/8b3fe5d4090afd9f502fb30a82026f87 to your computer and use it in GitHub Desktop.
Delete all post_meta.
<?php
class Meta_Reset {
function __construct() {
add_action( 'parse_request', [ $this, 'parse_request' ] );
}
/**
* Usage: mydomain.com/?meta_reset=1
*/
function parse_request() {
global $wpdb;
$table = _get_meta_table( 'post' );
$meta_keys = [
'_my_meta_key',
];
if ( isset( $_GET[ 'meta_reset' ] ) ) {
foreach ( $meta_keys as $meta_key ) {
$query = "DELETE FROM $table WHERE meta_key = '$meta_key'";
$wpdb->query( $query );
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment