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....
$args
ofget_tags()
is undefined. Debugging in WordPress$args = array()
before callingget_tags( $args )
, like in @shanebp answer. No warnings mean wrong error reporting configuration. See Display All PHP Errors: Basic & Advanced Usagehide_empty
was not ignored. It was not set! Btw, Undefined variable: args is not an Error but Notice. I suspect you see errors and don't see notices. Start your file withini_set('error_reporting', E_ALL);
and feel the difference. And, please, show me one of numerous examples you've mentioned to prove your rightness.