• Resolved kielie

    (@kielie)


    Hi, this is my first post on the wordpress forums, I really hope someone can help me out, here is what I am trying to achieve,

    I am trying to display all the child pages of a specific page as a list, as well as their custom fields, I am trying to populate a table where each row will have three columns, the first being the title of the child page, the second will be custom field one, and the third custom field two, so it would be something like this.

    <table>
    <tr>
        <td>the child pages title</td>
        <td>custom field one</td>
        <td>custom field two</td>
    </tr>
    </table>

    I tried using get_pages and wp_list_pages, but for some reason the custom fields won’t display.

    ANY help would be appreciated, I am still pretty new to wordpress and all it’s wonders!

    Thanx in advance!

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

    (@kielie)

    Ok, so after some more digging, I got it to work with this code, I hope it helps someone in future.

    <table width="750">
                        <?php
                        //get children of page 241 and display with custom fields
    
                        $args=array(
                          'post_parent' => 241,
                          'post_type' => 'page',
                        );
                        $my_query = null;
                        $my_query = new WP_Query($args);
                        if( $my_query->have_posts() ) {
    
                          while ($my_query->have_posts()) : $my_query->the_post(); ?>
    
                            <tr>
                                <td><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></td>
    
                                <!-- here I get the 'distDay' custom field's data, assign it to the $meta_one variable and echo it out !-->
                                <?php $meta_one = get_post_meta($post->ID, 'distDay', true); ?>
                                <td><?php echo $meta_one; ?></td>
    
                                <!-- here I get the 'printerOrder' custom field's data, assign it to the $meta_two variable and echo it out !-->
                                <?php $meta_two = get_post_meta($post->ID, 'printerOrder', true); ?>
                                <td><?php echo $meta_two; ?></td>
                            </tr>
                           <?php endwhile; } ?>
                        <?php wp_reset_query();  // Restore global post data stomped by the_post().?>
                    </table>
Viewing 1 replies (of 1 total)
  • The topic ‘Displaying child pages and their custom fields as a list !’ is closed to new replies.