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

Is possible to redirect category to first available child post please? Thanks!

share|improve this question

1 Answer 1

I had to do that, but only in some categories in my site. This was the code I used - I put it in my theme's functions.php:

  // use template_redirect action:
 add_action( 'template_redirect', 'my_redirect_to_post' );

 /// Function to redirect from certain category pages to first post of those categories
 function my_redirect_to_post() {
     if (is_category('3') ||  is_category('5') ) {
         $category = get_the_category();
         $posts =  query_posts('showposts=1&cat='.$category[0]->cat_ID);
         if(have_posts()) :

Of course, if you need to do it in all your categories, you can remove the condition if (is_category('3') || is_category('5') ).

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.