Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

WordPress

Stuart McPherson
Stuart McPherson
15,939 Points

Display Child page data: Title, featured image and custom field

I'm displaying the child pages of the current page. With the featured image, title pulling through. I also want to pull through a custom field I've added. I'm outputting this at html so it looks like each child page has its own box, with the featured image filling the box, the title on top of the image and the the custom field value sitting under the title.

But I can't get the custom field to display properly, I just get the value 1, not sure if I've converted the array properly?

Could you help me out to output the custom field 'PageTag'

Wordpress template code

<div class="childPages">
      <?php 
        $subs = new WP_Query( 
        array( 
          'post_parent' => $post->ID, 
          'post_type' => 'page', 
          'meta_key' => '_thumbnail_id' 
        )
      );
    if( $subs->have_posts() ) : 
      while( $subs->have_posts() ) : 
        $subs->the_post();
        $pageTag = get_post_meta($post->ID, '_PageTag' , true);
        echo '<div class="childPageBlock"> <a href="'.get_permalink().'" title="'.get_the_title().'">'.get_the_post_thumbnail().'</a>'.'<div class="childPageBlockText"><h3><a href="'.get_permalink().'">'.get_the_title().'</a></h3><span>'.print_r( $pageTag ).'</span></div></div>';
      endwhile; 
    endif; 
    wp_reset_postdata(); ?>
  </div>