• baga

    (@baga)


    Hello I’m using this code to get custom field values from childern pages:

    <?php
    $args = array(
        'post_type' => 'page',
        'post_status' => 'publish',
        'posts_per_page' => -1,
        'caller_get_posts'=> 1,
        'post_parent' => $post->ID
        );
      $my_query = null;
      $my_query = new WP_Query($args);
      if( $my_query->have_posts() ) {
        while ($my_query->have_posts()) : $my_query->the_post(); ?>
    <p><?php echo get_post_meta($post->ID, 'URL', true); ?></p>
    <?php endwhile;
      }
    wp_reset_query();
    ?>

    What should I add/modify to get the custom field values from granchildren pages?

Viewing 1 replies (of 1 total)
  • Thread Starter baga

    (@baga)

    After reading this topic: http://wordpress.org/support/topic/320566 I was able to solve the problem using this code:

    <?php
    $parent = $post->ID;
    $args = array(
        'post_type' => 'page',
        'post_status' => 'publish',
        'posts_per_page' => -1,
        'caller_get_posts'=> 1,
        'child_of' => $parent
    );
    $pages = get_pages($args);
    shuffle($pages);
    if ($pages) {
      foreach($pages as $post) {
        setup_postdata($post);
        if ($post->post_parent != $parent ) { ?>
    <p><?php echo get_post_meta($post->ID, 'URL', true); ?></p>
    <?php
    }
    }
    }
    wp_reset_query();
    ?>
Viewing 1 replies (of 1 total)
  • The topic ‘Get custom fields from grandchildren’ is closed to new replies.