Skip to content

Instantly share code, notes, and snippets.

@tlehtimaki
Created November 14, 2017 09:01
Show Gist options
  • Save tlehtimaki/768a02cb1b3b65fbb73a554b600716f4 to your computer and use it in GitHub Desktop.
Save tlehtimaki/768a02cb1b3b65fbb73a554b600716f4 to your computer and use it in GitHub Desktop.
Get wordpress page children ID's
<?php
// Setup $post
glopal $post;
// Store current post ID
$current_post_id = $post->ID;
// Note the slash here refers to global namespace.
$children = new \WP_Query(
array(
'post_type' => 'page',
'post_parent' => $current_post_id,
'fields' => 'ids'
)
);
array_unshift($children->posts,"{$current_post_id}");
$children_id_arr = $children->posts;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment