Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter John Leschinski

    (@picard102)

    Thought something like this might work, but not sure how to make it redirect the post to it’s category archive.

    <?php
    /*
    Template Name: Redirect To First Child
    */
    if (have_posts()) {
      while (have_posts()) {
        the_post();
        $pagekids = get_pages("child_of=".$post->ID."&sort_column=menu_order");
        $firstchild = $pagekids[0];
        wp_redirect(get_permalink($firstchild->ID));
      }
    }
    ?>

    This code will get the first category and redirect to that categories page. Put this code inplace of all code on the single.php and when a post is clicked this will happen:

    <?php
    $category = get_the_category();
    $category_id = $category[0]->cat_ID;
    $relocate = get_category_link($category_id);
    header("Location:".$relocate);
    ?>
    Thread Starter John Leschinski

    (@picard102)

    Works great! Thanks!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Redirect post to category archive.’ is closed to new replies.