Wordpress Display Child page data: Title, featured

2019-09-21 00:06发布

问题:

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'

https://i.stack.imgur.com/vzCBU.png https://i.stack.imgur.com/BwfuV.png

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().'<div class="childPageBlockText"><h3>'.get_the_title().'</h3><span>'.print_r( $pageTag ).'</span></div></a></div>';
   endwhile; 
 endif; 
 wp_reset_postdata(); ?>
</div>

回答1:

Removing the print_r() and leaving its as

'.$pageTag.'

Worked!



标签: wordpress