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);
?>
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);
?>
Share
Improve this question
asked Jun 25, 2020 at 19:01
bfoley_teamugbfoley_teamug
111 bronze badge
1
|
1 Answer
Reset to default 0You 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);
$arr
doing. It's doing nothing. It's just containing the arguments. You have to run the query first. – Sabbir Hasan Commented Jun 25, 2020 at 20:20