WordPress.org

Ready to get started?Download WordPress

Forums

Duplicated entries with get_posts (6 posts)

  1. spdy
    Member
    Posted 8 years ago #

    On my start page, I make use of the get_posts() function a couple of times. In all but one case the function works find and does what I want.

    The one that doesn't work just repeats one specific post a number of times (the post count for the specified category).

    Why could this be? Some sort of conflict?

    Here's the code:


    $recent_posts = get_posts('category=14');
    foreach($recent_posts as $r_post) : ?>

    -a>" title="<?php the_title(); ?>"><?php the_title(); ?></a-

    <?php endforeach; ?>

    This results in this:

    -a href="link-to-post" title="Hello World">Hello world</a-
    -a href="link-to-post" title="Hello World">Hello world</a-
    -a href="link-to-post" title="Hello World">Hello world</a-
    -a href="link-to-post" title="Hello World">Hello world</a-
    -a href="link-to-post" title="Hello World">Hello world</a-

    I can't find some sort of connection between things, so I'm completely clueless.

    PS. Dashes are for disabling anchor tags

  2. MichaelH
    Member
    Posted 8 years ago #

    <?php the_title(); ?>"><?php the_title(); ?>

    This in your code twice????

  3. spdy
    Member
    Posted 8 years ago #

    One time for the link title, one time for the actual link.

    The problem isn't just the title. It's that the loop outputs just one post, but several (five) times. Not five DIFFERENT posts...

  4. MichaelH
    Member
    Posted 8 years ago #

    spdy--Yes, I see that's a stupid answer. Maybe a link to your site so someone can help...

  5. spdy
    Member
    Posted 8 years ago #

    Sorry if I sounded harsh, wasn't my intention.

    Anyways, I can't link you do the site for various reasons, sorry. I just thought that someone would know some well-known conflicts that might cause this problem.

  6. MichaelH
    Member
    Posted 8 years ago #

    Not a problem spdy!

    Maybe put your template file (such as index.php) content in a paste bin such as: http://www.pastebin.com and report the link back here!

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags