0
Rooms
  Rooms 1
  Rooms 2
  Rooms 3
  Rooms 4

Rooms is the parent page and I want to display only the first child page.

Currently, I am using the code:

<?php
$args = array(
    'child_of' => 4,
    'title_li' => '',
    'sort_column' => 'post_date'
 );

 $pages = wp_list_pages($args);

It is fetching all the child pages. I am new to Wordpress coding and so need help.

2
  • The problem is that "first" needs a "order". So, first by what? By name? By ID? By date? Just first of whatever?
    – cybmeta
    Nov 14, 2016 at 7:49
  • First of whatever. For the question's sake, please assume Room 1 as first child page. u can take first by creation date. Nov 14, 2016 at 8:14

1 Answer 1

1

You can use get_pages with a limit of 1:

$pages = get_pages([
    'child_of' => $post->post_parent,
    'number'   => 1,
]);

if ( $pages ) {
    $first_page = current( $pages );
}
2
  • I tried this code, but not working Nov 15, 2016 at 5:30
  • Can you elaborate on "not working" Nov 15, 2016 at 10:12

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.