Last active
          August 29, 2015 14:10 
        
      - 
      
- 
        Save dboutote/62e4fac0600895d5b879 to your computer and use it in GitHub Desktop. 
    This checks if a parent page should load its first child page.
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | add_action( 'parse_request', 'check_for_redirect' ); | |
| function check_for_redirect( $query ) { | |
| if( is_admin() ){ | |
| return; | |
| } | |
| if( isset($query->query_vars[ 'pagename' ]) ){ | |
| $pagename = $query->query_vars[ 'pagename' ]; | |
| $parent_redirect_id = (int) get_option('parent_redirect_' . $pagename); | |
| if( $parent_redirect_id > 0 ){ | |
| $kids = get_pages("child_of=".$parent_redirect_id."&sort_column=menu_order"); | |
| if ($kids) { | |
| $kid = $kids[0]; | |
| $newpagename = $pagename . '/' . $kid->post_name; | |
| $query->query_vars[ 'pagename' ] = $newpagename; | |
| } | |
| } | |
| } | |
| return $query; | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
            
Requires a metabox to indicate that the page should redirect and an option set like so:
parent_redirect_{$pagename}with a value of the$pagename's ID