Support » Fixing WordPress » Get most recent post linking to wrong post

  • Charmeleon


    I’m using the following script to get the most recent post, display the title and link to post only (no post content), and truncate the post title to 75 characters or less:

    <?php $posts_query = new WP_Query('posts_per_page=1');
            while ($posts_query->have_posts()) : $posts_query->the_post();
        <a href="<?php the_permalink(); ?>"><?php
        if (strlen($post->post_title) > 75)
           echo substr($post->post_title, 0, 75) . ' ...';
           echo $post->post_title;
    ?>  </a>
        <?php endwhile; wp_reset_query(); ?>

    The script seems to display the most recent post title correctly, but it links to the second most recent post instead of the most recent post. What am I doing wrong?

    Any help would be appreciated. Thanks.

  • The topic ‘Get most recent post linking to wrong post’ is closed to new replies.