I have a custom post type testimonial and am trying to display the title, content and the featured image.
This is my code:
<?php
$args = array('posts_per_page' => -1, 'post_status' => 'publish', 'post_type' => 'testimonial');
$testimonialsposts = get_posts($args);
?>
<div class="row">
<?php
foreach ($testimonialsposts as $post)
{
setup_postdata($post);
?>
<div class="testimonial-box projectitem">
<img src="<?= get_post_meta($post->ID, '_wp_attached_file', true); ?>"/>
</div>
<div class="testimonial-contact">
<div class="testimonial-text"><?= get_post($post->ID, 'content', true); ?></div>
<div class="testimonial-name"><?= get_post($post->ID, 'post_title', true); ?></div>
<?php wp_reset_postdata();
} ?>
</div>
But I am getting nothing. When I tried to echo the details after setup_postdata its only echoing "array".
When I var_dump the $post it shows all the data also.
This is what i get when I var_dump
$post
object(WP_Post)#614 (24) { ["ID"]=> int(69) ["post_author"]=> string(1) "1" ["post_date"]=> string(19) "2017-08-22 02:26:43" ["post_date_gmt"]=> string(19) "2017-08-22 02:26:43" ["post_content"]=> string(575) "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum." ["post_title"]=> string(13) "testimonial_1" ["post_excerpt"]=> string(0) "" ["post_status"]=> string(7) "publish" ["comment_status"]=> string(6) "closed" ["ping_status"]=> string(6) "closed" ["post_password"]=> string(0) "" ["post_name"]=> string(11) "testimonial" ["to_ping"]=> string(0) "" ["pinged"]=> string(0) "" ["post_modified"]=> string(19) "2017-08-22 02:27:07" ["post_modified_gmt"]=> string(19) "2017-08-22 02:27:07" ["post_content_filtered"]=> string(0) "" ["post_parent"]=> int(0) ["guid"]=> string(63) "http://192.168.0.202/clinic202/?post_type=testimonial&p=69" ["menu_order"]=> int(0) ["post_type"]=> string(11) "testimonial" ["post_mime_type"]=> string(0) "" ["comment_count"]=> string(1) "0" ["filter"]=> string(3) "raw" }
What am I doing wrong?
print_r()
instead ofecho()
to display the contents of an array. If that doesn't help, please update your post to say if the array was empty or what it contained – FluffyKittenget_post
for some reason instead of just usingget_the_title
orget_the_content
, and you are not closing yourtestimonial-contact
div in the correct place. – FluffyKitten