1

Public query vars are those available and usable via a direct URL query.

E.g.

example.net/?category_name=tech&tag=gadgets

But doesn't example.net/?category_name=tech&tag=gadgets show an archive? It definitely uses the archive.php template, but for some reason, the is_archive(); conditional tag doesn't seem to work.

If is_archive(); isn't the conditional tag to check these archives with, what is?

2

Try this:

add_action( 'template_redirect', 'my_test_if_archive' );

function my_test_if_archive() {
  global $wp_query;
  $qv = array_keys( $wp_query->query );
  $archives = array('year', 'monthnum', 'day', 'w', 'm', 'author', 'post_type');
  $is_archive = ! empty( array_intersect( $qv, $archives ) );
  $is_tax = ! empty( $wp_query->tax_query->queries );
  if ( $is_archive || $is_tax ) {
    // this is an archive
  }
}
0

But doesn't example.net/?category_name=tech&tag=gadgets show an archive?

Yes, shows, (is_archive() returns true) however,

It definitely uses the archive.php

no, in this case, a category.php is used, if not found, then tag.php and if any of those files, archive.php displays your content.

According to template hierarchy, in wordpress an archive is everything, that displays a couple of posts, then it is divided into a category archive, a tag archive, a date archive…

EDIT

If is_archive(); isn't the conditional tag to check these archives with, what is?

For this purpose are used is_category(), is_tag()… whole bunch of them Conditional Tags

  • is_archive() returns true for category, tag, date, et al archives. So I don't understand the point of your answer. – its_me Nov 12 '13 at 14:10
  • My bad, maybe I did not get the full idea, what are you asking. I created an edit, you looking for such an info? – Ivan Hanák Nov 12 '13 at 14:16
  • No. Like I said earlier, in a way, is_archive() includes is_category(), is_tag, etc. -- all archives. But it's not working in my case. – its_me Nov 12 '13 at 14:29
  • ok, if you are satisfied with the solution a @G. M. came up with, be it, otherwise I am willing to discuss it to get to the root of the problem. Since, I just don't believe that a function, that is supposed to work, does not. If so, just tell me, in which template you use is_archive? – Ivan Hanák Nov 12 '13 at 14:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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