-
-
Save proweb/dbb3b3cb106e2fd96603879185a5bd33 to your computer and use it in GitHub Desktop.
WordPress redirection page template to the first child page (menu_order) with WPML handling
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
<?php | |
/** | |
* Template Name: Redirect to child page | |
* Description: Redirects to the top child page | |
* | |
* @package PUT YOUR THEME NAME HERE :D | |
*/ | |
global $post; | |
$parent = $post->ID; | |
// In case you use WPML | |
if ( defined( 'ICL_LANGUAGE_CODE' ) ) { | |
$_type = get_post_type( $post->ID ); | |
$parent = icl_object_id( $post->ID, $_type, true, ICL_LANGUAGE_CODE ); | |
} | |
$post_children = get_children( array( | |
'posts_per_page' => 1, | |
'orderby' => 'menu_order', | |
'order' => 'ASC', | |
'post_type' => 'page', | |
'post_status' => 'publish', | |
'post_parent' => $parent | |
) ); | |
wp_redirect( get_permalink( array_pop( $post_children )->ID ), 301 ); | |
exit; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment