WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Output a list of child pages of a particular parent ordered by custom field (9 posts)

  1. slee
    Member
    Posted 5 years ago #

    does anyone know how to output a list of child pages of a particular parent but order them by certain metadata?

  2. MichaelH
    Member
    Posted 5 years ago #

    This might work...didn't test though

    <?php
    $args=array(
      'showposts' => -1,
      'post_type' => 'page',
      'post_parent' => 93,
      'meta_key' => 'your_custom_field_here',
      'orderby' => 'meta_value'
    );
    $pages = get_posts($args);
    if ($pages) {
      foreach($pages as $post) {
        setup_postdata($post); ?>
        <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
        <?php
      } // foreach($pages
    } // if ($pages
    ?>
  3. slee
    Member
    Posted 5 years ago #

    that is great thanks yes it worked first time :)

  4. slee
    Member
    Posted 5 years ago #

    if i wanted to use this but page the output how would i go about doing that?

  5. MichaelH
    Member
    Posted 5 years ago #

  6. slee
    Member
    Posted 5 years ago #

    thanks ill shall have a look. is there any way of doing what you first gave me using the args method to use query_posts instead even though it is for pages?

  7. slee
    Member
    Posted 5 years ago #

    i managed to figure it out and ive got the paging working which is great i do have one final question. with the above code you have given will that also output children/children ? i only want it to output pages with the parent id of 116 so hopefully it won't output the children/children.

  8. MichaelH
    Member
    Posted 5 years ago #

    It was pretty easy to go back and create a grandchild page to test this--and no it didn't include that grandchild page.

  9. slee
    Member
    Posted 5 years ago #

    brilliant thanks for the help it is very much appreciated.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags