Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get all the post tags in WordPress?

Tags:

php

wordpress

I would like to get all the post tags in my WordPress. Below is my code in the footer:

<?php
global $wpdb;

$tags = get_terms('post_tag');
echo '<ul>';
foreach ($tags as $tag)
{
    echo '<li>' . $tag->name . '</li>';
}
echo '</ul>';
?>

With the above code I am getting only the tags associated with a specific post, not the entire list of tags in WordPress.

Any help will be appreciated. Thanks.

like image 358
theKing Avatar asked Jan 16 '17 09:01

theKing


1 Answers

Use get_tags to get all posts tags

<?php 
$tags = get_tags(array(
  'hide_empty' => false
));
echo '<ul>';
foreach ($tags as $tag) {
  echo '<li>' . $tag->name . '</li>';
}
echo '</ul>';
?>
like image 104
Rene Korss Avatar answered Oct 09 '22 03:10

Rene Korss