How to update incorrect post count in taxonomy?
I have imported a large amount of content using WPAllImport, all to a custom post type called "article" ("Articles") and all organised by a custom taxonomy type called "source" ("Sources").
However, on the edit-tags.php page for the Sources taxonomy listing, the Articles post counts are all inaccurate.
There is one term which shows as only having three Articles against it but, on the post index for Articles with that Source, it clearly has 1,997.
How can I fix all the counts?
I have tried to use wp_update_term_count_now
I tried ...
$update_taxonomy = 'source';
$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);
(via)
and the kitchen sink ...
$taxonomies = get_taxonomies();
foreach( $taxonomies as $taxonomy ) {
$args = array(
'hide_empty' = 0,
'fields' = 'ids'
);
$terms = get_terms( $taxonomy, $args );
if( is_array( $terms ) !empty( $terms ) ) wp_update_term_count_now( $terms, $taxonomy );
}
(via)
But neither seems to do anything.
I put the code in a header.php theme file just to execute.