0

I'm trying to build a nav out of an array of child pages from a custom post type called "section" with a parameter depth of 1. I want to slice this array so that it only displays a part of the array. When I try array_slice() or array_chunk() and then wp_list_pages() to display the pages, it returns everything from the Pages content type and it doesn't split up the array either. What am I doing wrong?

<?php
                 $arr = array(
                    //$section_top_parent is the top parent of the custom post type "section"
                   'child_of' => $section_top_parent,
                   'post_type' => 'section',
                   'title_li' => NULL,
                   'depth' => 1,
                   'sort_order' => 'asc',
                  );

                  $sliced = array_slice($arr, 3, 5);
                  wp_list_pages($sliced);

                 $chunk = array_chunk($arr, 3);
                 wp_list_pages($chunk);

                  ?>
1
  • look carefully what your $arr doing. It's doing nothing. It's just containing the arguments. You have to run the query first. Jun 25 '20 at 20:20
0

You need to do the slice on the results, not the arguments to the function. So:

$arr = array(
    //$section_top_parent is the top parent of the custom post type "section"
    'child_of' => $section_top_parent,
    'post_type' => 'section',
    'title_li' => NULL,
    'depth' => 1,
    'sort_order' => 'asc',
);

$result = wp_list_pages($arr);
$sliced = array_slice($result, 3, 5);
wp_list_pages($sliced);

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.