Get array of child message ids, wordpress 3.0, php

Ok here is one for ya ...

In a custom template, I use this code to retrieve and display a list of child pages / posts

$args = array(
                    'depth'        => 1,
                    'show_date'    => '',
                    'date_format'  =>     get_option('date_format'),
                    'child_of'     => $post->ID,
                    'exclude'      => '',
                    'include'      => '',
                    'title_li'     => '',
                    'echo'         => 1,
                    'authors'      => '',
                    'sort_column'  => 'menu_order, post_title',
                    'link_before'  => '',
                    'link_after'   => '',
                    'walker' => '' );

                    wp_list_pages( $args );

This works great, I'm also wondering how I can get / create arraychild message ids. My goal is to access some metadata custom fieldsthrough the function of get_post_meta()each child message using its ID.

Thanks guys.

+3
source share
3 answers

I think I was not very clear with this, since this is the first time I have never received a response from SO.

I managed to find the information I needed and put it here for everyone who views the same request.

ok - ID..

$pages = get_pages('child_of=X');
    foreach($pages as $child) {

    // Now you have an object full of Children ID that you can use for whatever
    // E.G 
    echo $child->ID . "<br />";
}
+6

, :

$pageids = array();
$pages = get_pages('child_of=X');
    foreach($pages as $page){
     $pageids[] = $page->ID;
}

.

+3
$children = get_posts('post_parent=SLUG_OF_PARENT_POST&post_status=publish');
foreach($children as $child)
{
echo '<br/>ID:'.$child->ID;
}

you can use other attributes (i.e. $child->post_content) ... if you need to define post_type, add this argument as well:&post_type=POST_TYPE_NAME

0
source

Source: https://habr.com/ru/post/1793419/


All Articles