I need a list of post tags, only the tags present in the posts shown in a paged front page. So, my first step is to build an array with this tags. This is what I did:

1. Declare an array in the global scope (front-page template)

$filtros = array();

2. Inside loop, get the tags of each post and add it to the array

$posttags = get_the_tags();
if ($posttags) {
  foreach($posttags as $tag) {
    if( !in_array( $tag->name ,$filtros ) ) {
      array_push($filtros, $tag->name);

I have two questions:

1. If array was declared, why return this warning?

 Warning: array_push() expects parameter 1 to be array, null given.

2. Once I have the array working, how can I update the tag list?

I mean, the tag list must be present in the header, before the loop, but the tag array was built after the loop. Can I update the tag list rendered before the loop with an array built after the loop?

Thank you in advance.

1 Answer 1


$filtros = array(); will always returns null, meaning it's an empty array.

To make your code works, you can try :

   $filtros[] = $tag->name;

instead of array_push(),

Hope it works after!


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.