WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a few categories.

in each of them, I have only one post.

by clicking on a category, I have to click on that single post to enter.

I wish, by clicking on the category, enter directly in that one post.

This method avoids having to click two times in the post.

Any suggestions for what I have to use code in archive.php?

share|improve this question
up vote 4 down vote accepted

this function will check if you're on a category page and 302 redirect to the latest post in that category. put it in your theme's functions.php file.

function my_check_if_cat(){
    if ( is_category() ) :
        $category = get_the_category();
        $latest = query_posts('showposts=1&cat='.$category[0]->cat_ID);
        if(have_posts()) :
            wp_redirect(get_permalink($post->ID), 302);
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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