• I’m using query_posts to display posts from one category on a page (not home). Using this code:

    ‘[php]
    require(‘../wp/wp-load.php’);
    query_posts( array (‘category_name’ => ‘Teams’, ‘posts_per_page’ => -1, ‘orderby’ => ‘title’, ‘order’ => ‘ ASC’));
    while (have_posts()): the_post();
    the_content();
    endwhile;
    echo ‘End’;
    [/php]‘

    where there is one post in the Teams category results in the post followed by the echoed ‘End’ followed by the same post again. http://illinoisladylightning.com/wp/test/

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator t-p

    (@t-p)

    do not use query_posts(), but rather use WP_Query() as the link by @tara suggested.

    Thread Starter jonjvaughn

    (@jonjvaughn)

    Very good and thank you. I don’t understand exactly why the old code failed other than to say that it isn’t the currently desired technique? I changed the above code to this and it works fine


    $query = new WP_Query( array( ‘post_type’ => ‘post’, ‘category_name’ => ‘Teams’ ) );
    while ($query->have_posts()): $query->the_post();
    the_content();
    endwhile;
    wp_reset_postdata();

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘query_posts results in duplicates’ is closed to new replies.