WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] list of children as array (8 posts)

  1. thetooon
    Member
    Posted 4 years ago #

    Is there any way to return as array all children of the parent page?

    get_children _list doesn't seem to work in such way.

    Should I hack into wp_query()?

  2. Mark / t31os
    Moderator
    Posted 4 years ago #

    Can you be more specific, what are you trying to get, and in what context?..

    Alot of functions return items as an array or an object, and sometimes that's optional, depending on the function.

    Can you give me a usage example, and i'll try to offer an alternative to what you've tried.

  3. thetooon
    Member
    Posted 4 years ago #

    According to Page & Post parameters the following code suppose to return something with children:

    $allsearch = &new WP_Query("post_parent=3&showposts=-1");
    echo '<pre>'; var_dump($allsearch); echo '</pre>';

    but it doesn't...

  4. thetooon
    Member
    Posted 4 years ago #

    I'm trying to get childre list of specific page as array, that's it.

  5. Mark / t31os
    Moderator
    Posted 4 years ago #

    WP_Query is an object, to see the results you need to call the necessary methods of the WP_Query class, like you'd see with a regular loop.. to iterate over the results ..

    if( $allsearch->have_posts() ) :
    while( $allsearch->have_posts() ) : $allsearch->the_post()
    
    // STUFF
    
    endwhile;
    endif;

    Does that help?

    Suggestion, if this isn't suited, take a look at get_posts()

  6. thetooon
    Member
    Posted 4 years ago #

    Doesn't help at all.

    I need simple call to get the list of children's IDs as ARRAY.

    Don't need pages themself.
    Don't need complicated hacks.
    Don't need invent a wheel.

    Need bloody array with ids. Nothing else.

  7. Mark / t31os
    Moderator
    Posted 4 years ago #

    See the information here regarding selecting just a column of data.
    http://codex.wordpress.org/Function_Reference/wpdb_Class#SELECT_a_Column
    and..
    http://codex.wordpress.org/Function_Reference/wpdb_Class#SELECT_Generic_Results

    I generally use the get_col method when i'm selecting just post ids as this is obviously more efficient than a query consisting of unneeded post data (content, title, etc..).

  8. thetooon
    Member
    Posted 4 years ago #

    Well, I used FlexiPages plugin finally.

Topic Closed

This topic has been closed to new replies.

About this Topic