You have made the mistake in getting the post link in your code.
Missing
<?php global $post; ?>
– Initialization at the start of the loop
After setting up the post data your query becomes like normal
Wp_Query
so that you can get thepermalink()
in normal method itself usingthe_permalink()
instead ofget_permalink($post->id)
.
Since your posts is behaving in the normal method you need to make the following changes.
- Remove the
get_permalink()
from the code - Remove the echo tag in roder to display the permalink
Replace your code with the current one.
Wherever you have used
<?php echo get_permalink($post->ID); ?>
Replace it with
<?php the_permalink(); ?>
And your final code will look like as follows.
<?php $posts = get_posts( "category=17,12,35,23,24,25,13,27,14,26,22,16,29,15,19,20,21&numberposts=3" ); ?>
<?php if( $posts ) : ?>
<?php global $post; ?>
<?php foreach( $posts as $post ) : setup_postdata( $post ); ?>
<div class="post homepage">
<a href="https://wordpress.stackexchange.com/questions/240856/<?php the_permalink(); ?>"><img src="<?php $feat_image = wp_get_attachment_url( get_post_thumbnail_id($post->ID) ); echo $feat_image;?>" /></a>
<h3 class="homepage-post-title"><a href="https://wordpress.stackexchange.com/questions/240856/<?php the_permalink(); ?>"><?php echo $post->post_title; ?></a></h3>
<a class="read-more-link" href="https://wordpress.stackexchange.com/questions/240856/<?php the_permalink(); ?>">Read More</a>
</div>
<?php endforeach; ?>
<?php endif; ?>