The sort_column
parameter of wp_list_pages()
does allow items to be returned in random order using the rand
option.
sort_column
(string) Comma-separated list of column names to sort the pages by. Accepts ‘post_author’, ‘post_date’, ‘post_title’, ‘post_name’,
‘post_modified’, ‘post_modified_gmt’, ‘menu_order’, ‘post_parent’,
‘ID’, ‘rand’, or ‘comment_count’. Default ‘post_title’.
add_shortcode( 'wpb_childpages', 'wpb_list_child_pages' );
function wpb_list_child_pages() {
global $post;
if ( is_page() && $post->post_parent ) {
$childpages = wp_list_pages( 'sort_column=rand&title_li=&child_of=" . $post->post_parent . "&echo=0' );
} else {
$childpages = wp_list_pages( 'sort_column=rand&title_li=&child_of=" . $post->ID . "&echo=0' );
}
if ( $childpages ) {
$string = '<ul>' . $childpages . '</ul>';
}
return $string;
}