I have this code below, and I wish to show each link of each post, but I keep getting same link to all posts which is the link of the page.

$args = array('posts_per_page' => 5,'order' => 'DESC');
$rp = new WP_Query($args);
if($rp->have_posts()) :
while($rp->have_posts()) : $rp->the_post();

   the_title(); 

$link=the_permalink();
echo '<a href="'.$link.'">Welcome</a>';
echo "<br />";

endwhile;

wp_reset_postdata(); 

endif;

Thank you.

3 Answers
3

Don’t forget to use esc_url()

echo '<a href="'. esc_url( $link ).'">Welcome</a>';

Also try this: get_permalink( get_the_ID() );

Leave a Reply

Your email address will not be published. Required fields are marked *