WordPress.org

Support

Support » Plugins and Hacks » show only grand children

show only grand children

  • i am using something like this:

    $args=array(
    ‘post_type’ => ‘page’,
    ‘post_parent’ => 116,
    ‘meta_key’ => $key,
    ‘meta_value’ => $mvalue,
    ‘orderby’ => $orderby,
    ‘posts_per_page’ => 50,
    ‘order’ => $order
    );
    query_posts($args);

    but is there a way i can only show the grandchildren ie children’s children?

Viewing 9 replies - 1 through 9 (of 9 total)
  • Use get_pages and something like this in your loop:

    if ($post->post_parent != 116 ) {

    i have tried this:

    $args=array(<br />
    		  'post_type' => 'page',<br />
    		  'orderby' => $orderby,<br />
    		  'posts_per_page' => 50,<br />
    		  'child_of' => 116,<br />
    		  'order' => $order<br />
    		);<br />
    		get_pages($args);

    with if ($post->post_parent != 116 ) {as you suggested in the loop,

    but that is only returning a link to the page that this is running on???

    can i use it with the normal loop or doi have to use a foreach loop?

    You would need a loop of some kind to iterate through the array of pages returned by get_pages.

    Could use the same code I gave you in your other thread, but use this instead of the get_posts/query_posts

    $args=array(
    'post_type' => 'page',
    'post_parent' => 116,
    'meta_key' => $key,
    'meta_value' => $mvalue,
    'orderby' => $orderby
    );
    $pages = get_pages($args);

    i really appreciate your help but using that with the previous code doesn’t output anything even before i put the if ($post->post_parent != 116 ) {

    i hav added two pages that are children of two different pages that have the parent of 116 so i should get 2 pages outputted.

    if i remove the meta_key, meta_value and the orderby then i get every single page.

    Well I used this with success:

    <?php
    echo 'get pages';
    $parent = 93;
    $args=array(
      'child_of' => $parent
    );
    $pages = get_pages($args);
    if ($pages) {
      foreach($pages as $post) {
        setup_postdata($post);
        if ($post->post_parent != $parent ) { ?>
          <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
    ?>

    ah it was because i still had:

    ‘post_type’ => ‘page’,

    which obviously isnt needed any more

    thanks for the help 🙂

    i have hit a problem with this, i want to be able to filter the results by using meta_key and meta_value but when i use the meta_value it does not work.

    i have simply got `’meta_key’ => $key,
    ‘meta_value’ => $mvalue,`

    which then using get capture the value but even if i hardcode them they don’t work.
    i have a custom field called location and i have 1 page with the value Greece but if i use meta_value greece with meta_key location nothing is outputted am i doing something wrong?

    This works okay for me:

    <?php
    echo 'get pages';
    $parent = 93;
    $args=array(
    'child_of' => $parent,
    'meta_key' => 'cf1',
    'meta_value' => 'cf1 value'
    );
    
    $pages = get_pages($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
    ?>

    i tried your code replacing he cf1 with location and greece for the value but nothing was outputted. when you tested it did you try it with the grandchildren?

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘show only grand children’ is closed to new replies.
Skip to toolbar