admin管理员组文章数量:1332361
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);
本文标签: arrayWhy are arrayslice() and arraychunk() not working
版权声明:本文标题:array - Why are array_slice() and array_chunk() not working? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742318225a2452248.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
$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