Skip to content

Instantly share code, notes, and snippets.

@kadimi
Last active March 24, 2024 21:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kadimi/8340aab53137a951674450d64199063a to your computer and use it in GitHub Desktop.
Save kadimi/8340aab53137a951674450d64199063a to your computer and use it in GitHub Desktop.
SportsPress: Find duplicated variable/key instances
<?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