Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

get_permalink() return duplicate URL during loop

I’m trying to show some posts in my slider; But this loop returns same link for all items

$recent_posts = get_posts(array('posts_per_page' => '6‍', 'meta_key' => 'post_views_count', 'orderby' => 'meta_value_num', 'order' => 'DESC'));
foreach ($recent_posts as $post_item) : ?>
    <?php $author_id = $post->post_author; ?>
        <a href="<?= get_permalink($post) ?>" class="special-slide">
            <?php echo get_the_post_thumbnail($post_item, 'full'); 
        </a>
<?php endforeach; ?>

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

You have a small mistake on the 4th line: you’re calling get_permalink($post) where $post is set for the current page, where you should have used get_permalink($post_item) – where $post_item is the variable from your loop.

(You’re also making the same mistake on the 3rd line when you’re trying to get the author_id as well)

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading