Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- Plugin Name: Polylang database correction
- */
- /*
- Correct a the database when tags and/or categories are duplicated with Polylang activated (an not with Polylang deactivated)
- See: http://wordpress.org/support/topic/plugin-polylang-categories-and-tags-are-duplicated
- Polylang must be activated for this plugin to work
- Make a backup of your database
- Copy paste in a file correct.php
- Upload the file in the plugins directory
- Activate the plugin -> it should immediately remove duplicate tags and categories
- Deactivate the plugin and delete it
- */
- add_action('init', 'pll_correct_db', 100); // after Polylang
- function pll_correct_db() {
- global $polylang, $wpdb;
- if (!isset($polylang))
- return;
- $meta_ids = $wpdb->get_col("SELECT meta_id FROM $wpdb->termmeta AS tm WHERE tm.meta_key = '_language'");
- $terms = $wpdb->get_col("SELECT term_id FROM $wpdb->termmeta AS tm WHERE tm.meta_key = '_language'");
- $unique = array_unique($terms, SORT_NUMERIC);
- foreach (array_keys(array_diff_key($terms, $unique)) as $key)
- $to_correct[] = $meta_ids[$key];
- if (isset($to_correct)) {
- $query = $wpdb->prepare("DELETE FROM $wpdb->termmeta WHERE meta_id IN( ". implode( ',', $to_correct ) ." )");
- $wpdb->query($query);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement