Quantcast
Channel: WordPress.org Forums » All Topics
Viewing all articles
Browse latest Browse all 82367

is the polylang startpage i’m redirected to, different then other pages?

$
0
0

Replies: 1

Hi,

with the following function and the template_redirect hook, i’m redirecting a parent page to first child page based on menu_order. This is working fine on all pages, except the startpage where I’m redirect to by polylang.

In this case, I get the error ‘Trying to get property of non-object)’ because of $post isn’t set.

Is there something different on the Polylang startpage? If I’m accessing domain.com/en/startpage, it is working fine. If I’m accessing domain.com then polylang is redirecting to domain.com/en/ and it is not working.

I thought domain.com/en/ is the same like domain.com/en/startpage. (I’ve chosen to display the front page as a static page in Settings > Reading)

function weParentPageRedirect() {

global $post;

// get child pages
$child_page = get_pages( “child_of=” . $post->ID . “&sort_column=menu_order” );

if ( $child_page ) {
// get id of first child page
$firstchild = $child_page[0];
wp_redirect( get_permalink( $firstchild->ID ), 301 );
exit();
}

}
add_action( ‘template_redirect’, ‘weParentPageRedirect’ );

Thanks!


Viewing all articles
Browse latest Browse all 82367

Trending Articles