Why does 'hierarchical' not work in Get_Pages? (14 posts)

  1. researcher
    Posted 7 years ago #

    so i have this page that has to show ONLY the children of the present parent, not the grandchildren.
    after a long search i found this code:

    <?php $pages = get_pages('child_of='.$post->ID.'&sort_column=menu_order&hierarchical=0');
    				$count = 0;
    					foreach($pages as $page) {
    					$content = $page->post_content;
    				if($count >= 8)
    					$content = apply_filters('the_content', $content);
    			<li><a href="<?php echo get_page_link($page->ID) ?>"><?php echo $page->post_title ?></a>
    				<div class="locationentry"><?php echo $content ?></div>
    		<?php } ?>

    does anyone know why the 'hierarchical=0' is not working in Get_Pages or "what is wrong in the get_pages code"?

    if you are looking at this page you have to know that green blocs #2 and #3 are children of green bloc #1

    any help is very welcome, thnx for your time.

  2. iridiax
    Posted 7 years ago #

    WordPress functions have only certain parameters that they will accept. Check out: http://codex.wordpress.org/Function_Reference/get_pages

    Also check out:


  3. researcher
    Posted 7 years ago #

    thnx iridax for your fast response
    the code i use comes from that pages.
    the hierarchical is almost at the bottom of that page.
    i've tried all combinations now, no result.

  4. iridiax
    Posted 7 years ago #

    I think that child_of (subpages only) and hierarchical (parent page with indented subpages) conflict.

  5. researcher
    Posted 7 years ago #

    iridiax the child_of has to be there to produce the subpage from the parent. but the then the parent page refuses to block the children.
    could this be a conflict?
    i have tried all combinations already, all sub pages are there.

  6. iridiax
    Posted 7 years ago #

    I don't think that you can use these two parameters together.

  7. researcher
    Posted 7 years ago #

    this is a kind of strange. both parameters where in the description.
    are talking about a bug?

  8. iridiax
    Posted 7 years ago #

    Some function parameters do conflict, and the Codex usually mentions this, but I unfortunately don't see mention of it on this function's description page.

  9. researcher
    Posted 7 years ago #

    and now?
    how to solve this problem, any idea's?

  10. iridiax
    Posted 7 years ago #

    Maybe you could try a different function, multiple functions, or a custom query?

  11. researcher
    Posted 7 years ago #

    i think you are right.
    perhaps i try the get_categories for this job.
    the get_pages function is too buggy.

  12. researcher
    Posted 7 years ago #

    i found this workaround to a bug in both wp_list_pages and get_pages depth and hierarchical.
    you can ad a meta_key to the selection with the position of the page: parent, child, grandchild and so on.
    that line should look like:
    $pages = get_pages('child_of='.$post->ID.'&sort_column=menu_order&meta_key=Child_Loc&title_li=');
    don't forget to ad the meta_keys to your pages.

  13. mijk
    Posted 7 years ago #

    hierarchical=0 didn't work for me either, so I have used this and now WP is displaying only first level of pages:

    if( is_page() ) $curpage = $post->ID;
    $pages = get_pages('parent=0&hierarchical=0&sort_column=menu_order');
    foreach( $pages as $page ) {...
  14. guras
    Posted 6 years ago #

    Hi, I just solved the problem in the different way. I added to /wp-content/themes/default/style.css line:

    #sidebar ul ul ul li{display:none;}

    so it's a small workaround of the thing :D

Topic Closed

This topic has been closed to new replies.

About this Topic