0

I have problem displaying child page content on parent page (both static). I can display other page content but only if on same level. It dosent work in relation parent - child.

<?php
    $investor_content_query = new WP_Query( array(
        'pagename'    => 'current',
        'post_parent' => 'investor-relations'
    ) );
    if ( $investor_content_query->have_posts() ) {
        while ( $investor_content_query->have_posts() ) {
            $investor_content_query->the_post();
            the_content();
        }
    }
    wp_reset_postdata();
?>
1

You were being too specific/not passing the correct parameters into your wp_query. This should get you what you're looking for:

<?php
$current_page_id = get_the_id();
$investor_content_query = new WP_Query( 'post_parent'=> $current_page_id ) );
if ( $investor_content_query->have_posts() ) {
    while ( $investor_content_query->have_posts() ) {
        $investor_content_query->the_post();
        the_content();
    }
}
wp_reset_postdata();
?>
  • tried this but doesn't work. – Maciek Wrona Mar 26 '16 at 14:54
0

Ok, i found solution. What I really needed was parent page slug in "pagename" argument.

'pagename'=> 'investor-relations/current'

And working solution:

<?php
    $investor_content_query = new WP_Query( array(
        'pagename'=> 'investor-relations/current'
    ) );
    if ( $investor_content_query->have_posts() ) {
        while ( $investor_content_query->have_posts() )
        {
            $investor_content_query->the_post();
            the_content();
        }
    }
    wp_reset_postdata();
?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.