Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save artlung/de0f46d0d38da0ddaa6734000453ebae to your computer and use it in GitHub Desktop.
Save artlung/de0f46d0d38da0ddaa6734000453ebae to your computer and use it in GitHub Desktop.
<?php
$current_dir = dirname(__FILE__);
// load wordpress functions
require_once( $current_dir . '/../../../wp-load.php');
$years = range(2001, date('Y'));
$ignored_permalinks = [
'https://artlung.com/blog/2002/02/02/9309543/',
'https://artlung.com/blog/2002/03/07/10513352/',
'https://artlung.com/blog/2003/02/17/89271672/',
'https://artlung.com/blog/2003/11/13/106878821057274262/',
'https://artlung.com/blog/2003/11/25/106977880838835072/',
'https://artlung.com/blog/2005/06/03/insomniac-cinema/',
'https://artlung.com/blog/2005/07/10/rose-1986/',
'https://artlung.com/blog/2005/11/11/loretta-letter-lyrics-bagdad-cafe/',
'https://artlung.com/blog/2007/03/08/new-theory-of-technology-work/',
'https://artlung.com/blog/2007/04/09/stray-data/',
'https://artlung.com/blog/2007/04/20/passing-strange-discounted/',
'https://artlung.com/blog/2021/12/21/sig/',
'https://artlung.com/blog/2024/02/26/extracting-hex-color-php/',
'https://artlung.com/blog/2024/02/29/leap-day/',
'https://artlung.com/words/what-is-a-web-integrator/',
'https://artlung.com/blog/2004/04/22/108267512416373783/',
'https://artlung.com/blog/2004/04/26/108298910583538015/',
'https://artlung.com/blog/2004/05/17/108482064643201332/',
'https://artlung.com/blog/2004/06/15/108733298675033889/',
];
foreach ($years as $year):
$args = [
// type post
'post_type' => ['post', 'page'],
'posts_per_page' => -1,
'post_status' => 'publish',
'orderby' => 'date',
'order' => 'ASC',
'date_query' => [
[
'year' => $year,
],
],
];
$posts = get_posts($args);
printf("Year: %s\n", $year);
// find posts with 4 or more asterisks
foreach ($posts as $post) {
if (in_array(get_permalink($post->ID), $ignored_permalinks)) {
continue;
}
$content = $post->post_content;
$asterisks = substr_count($content, '*');
// lots of underscores in permalinks, ignore those
$underscores = substr_count(strip_tags($content), '_');
$url = get_permalink($post->ID);
if ($asterisks > 3 || $underscores > 3) {
if ($asterisks) {
printf("Post %s has %s asterisks\n", $post->ID, $asterisks);
}
if ($underscores) {
printf("Post %s has %s underscores\n", $post->ID, $underscores);
}
printf("URL: %s\n", $url);
}
}
endforeach;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment