dylanjameswagner
8/21/2015 - 6:59 PM

WordPress: Page Template: Redirect to First Child

WordPress: Page Template: Redirect to First Child

<?php
/**
 * Template Name: Redirect to First Child
 */
$id = $post->ID;
$children = get_pages([
  'parent'      => $id, // required
  'child_of'    => $id, // required
  'sort_column' => 'menu_order',
  'number'      => 1,
]);
header('Location: ' . get_permalink($children[0]->ID));