Why are array_slice() and array_chunk() not working?

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);

                  ?

Topic wp-list-pages array Wordpress

Category Web


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);

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.