Skip to content

Instantly share code, notes, and snippets.

@GaryJones
Last active August 6, 2018 13:13
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 GaryJones/a5b9e939a8860308dc54c198dec607db to your computer and use it in GitHub Desktop.
Save GaryJones/a5b9e939a8860308dc54c198dec607db to your computer and use it in GitHub Desktop.
Fix WordPress category (or other taxonomy) counts, after incomplete import, etc.
<?php
// Can drop into {yourtheme}/functions.php and then hit the site.
$update_taxonomy = 'category'; // Set to the correct taxonomy.
$get_terms_args = array(
'taxonomy' => $update_taxonomy,
'fields' => 'ids',
'hide_empty' => false,
);
$update_terms = get_terms( $get_terms_args );
wp_update_term_count_now( $update_terms, $update_taxonomy );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment