I have a client who wants to review and revise their Tags and tagging strategy, but they want to start with a spreadsheet of ALL tags, including those that have no posts assigned to them.
SO I created a template that outputs the Tags to an HTML Table, that I can then import into Excel and upload to Google Sheets so their team can collaborate on it.
The template works great, but the query does not include the empty Tags, even though I have "hide_empty" set to 0 (tried both 'false' and '0' with the same results).
I can't use get_terms because that query includes terms added by plugins that are not at all related to Posts nor post_tags, even though when I tried get_terms I added the 'taxonomy' => post_tag, it still gave me about 400 additional terms that are not Post Tags (they are mostly for CPTs and the like, not Posts).
If I use get_tags, I get a clean list of just Post Tags, but it isn't giving me the ones with 0 Posts assigned.
Can someone please help me troubleshoot this code?
Here is the HTML and query from my Template:
<table id="download"> <tr> <th>Tag Name</th> <th>Post Count</th> </tr> <?php global $wp_query; $tags = get_tags( $args ); $args = array( 'hide_empty' => 0, ); if ( $tags ) : foreach ( $tags as $tag ) : ?> <tr> <td><?php echo esc_html( $tag->name ); ?></td> <td><?php echo $tag->count; ?></td> </tr> <?php endforeach; endif; ?> </table>
I know there are quite a lot of Tags in their list that have 0 Posts assigned, I can see them in the WP back end, just can't figure out how to export the entire list to something someone can work with in Excel/Google Sheets....