Get the post thumbnail with wp_query

I am trying to get the post thumbnail to show in line with these other functions and am having no luck:

Info:

<?php echo '<h2><a href=\"' . get_permalink($attractions->post->ID) . '\">' . get_the_title($attractions->post->ID) . '</a></h2>' . get_the_post_thumbnail($attractions->post->ID, 'full') ;?>

I have tried all variations from Googling for an hour and cannot figure this out.

Any suggestions would be great.

1 Answer
1

If you are using this inside the loop of your WP_Query then why are you providing the Post ID parameter in functions. You don’t need to do that.

So your code will become this.

<?php echo '<h2><a href="' . get_permalink() . '">' . get_the_title() . '</a></h2>' . get_the_post_thumbnail( get_the_ID(), 'full' ); ?>

And please read the answer and explanation by @PieterGoosen. He well explained how WordPress functions usually works. And how can you echo the results with get_ prefix.

Also you were using \ before double quote which you don’t need to do here.

Leave a Comment