I'd like to shorten this code and instead of manually placing all children Id's, I'd like to pull out only the id's and set it to array. this could be something dynamic in the future when they are adding new child page from the parent page.

if ( in_array($post->ID, ['39','41','43','45']) ) {
  $menuPage = 'about';
} elseif ( in_array($post->ID, ['47','49','51','53','55','57']) ) {
  $menuPage = 'asset';

get_template_part( _menu, $menuPage );

I tried some codes but it technically display the title only. Where I am currently using similar to this code.

<ul class="uk-nav uk-navbar-dropdown-nav uk-list uk-list-inline">
  $args = array(
      'depth' => 1,
      'include' => 15,
      'title_li' => '',
  $args['child_of'] = $args['include'];
  • what exactly are you trying to check with those page IDs? it seems to me that you have two parent pages, and, depending on the current (child) page, you are calling a different template part?
    – Michael
    Commented Feb 1, 2018 at 3:02
  • 1
    Caiovisk put my case to rest. Get WordPress Child Page IDs Commented Feb 1, 2018 at 4:34

1 Answer 1

$args = array(
    'post_type'   => 'page',
    'post_parent' => 'your_parent_page_ID',

$query = new WP_Query( $args );
if ( $query->have_posts() ) :
    echo '<ul>';
    while ( $query->have_posts() ) :
        echo '<li>' . get_the_ID() . '</li>';
    echo '</ul>';

Put your parent page ID intead of your_parent_page_ID and you will recieve list with child pages id.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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