Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
142 views
Welcome To Ask or Share your Answers For Others

1 Answer

Removing the print_r() and leaving its as

'.$pageTag.'

Worked!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...