Tags – Can I build my own query in WordPress the traditional way?

I am new to developing themes with wordpress, so here is my question. Can I build my own query in WordPress the traditional way?

I know we use WP query methods, but what is the most efficient way, and can I use my own SQL commands to generate a query for all tags with published posts? For example.

I am using get_the_tags() with wordpress, but it is only providing tags related to the post. I want to display all tags containing published posts. And now come to think of it, I think it’s not even displaying the tag, only the post category, so I must be doing something wrong.

Below is the code in functions.php file

 function get_all_tags(){
    $posttags = get_the_tags('');
    if ($posttags) {
        foreach($posttags as $tag) {
            echo '<li><a href="#">'.$tag->name.'</a></li>'; 
        }
    }
}

In Single.php file, I am calling this function.

<?php $tagsAll = get_all_tags(); echo $tagsAll; ?>

I’ve picked up some of these from online searches, but I’ve been trying to modify for all tags with little success. Thank you

Leave a Comment