WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

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

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

share|improve this question

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.