Last active
March 24, 2024 21:58
-
-
Save kadimi/8340aab53137a951674450d64199063a to your computer and use it in GitHub Desktop.
SportsPress: Find duplicated variable/key instances
This file contains hidden or 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 (!empty($_GET['sportspress_debug'])) { | |
add_action('init', function () { | |
$all = []; | |
foreach ([ | |
'sp_outcome', | |
'sp_result', | |
'sp_performance', | |
'sp_column', | |
'sp_metric', | |
'sp_statistic', | |
'sp_spec', | |
] as $cpt) { | |
$posts = get_posts([ | |
'post_type' => $cpt | |
]); | |
foreach ($posts as $post) { | |
$all[] = [ | |
'id' => $post->ID, | |
'slug' => $post->post_name, | |
'cpt' => $cpt, | |
]; | |
} | |
} | |
$duplicates = array_values(array_filter($all, fn ($element) => array_count_values(array_column($all, 'slug'))[$element['slug']] > 1)); | |
print_r($duplicates); | |
die(); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment