SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    Sep 2006
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Recent Posts get Duplicated

    Hi, sorry about my english, I'm try to explain the best I can, and thank you in advance for your support and advice.

    Ok i have the following code in a widget area, since i used this code before everything work ok, starting this year for some estrange reason now isn't working:

    This is the way that used to work:

    Latest Videos Post (Proved Working Scenario)
    3. Best warm-up exercises2 (date: Dec20, 2011, categories: [Videos, ExampleCat1], Image:featured image3)
    2. Best warm-up exercises1 (date: Dec 5, 2011, categories: [Videos, ExampleCat1], Image:featured image2)
    1. Preventing concussion Video 1 (date: Dec 1, 2011, categories: [Videos, Preventing, ExampleCat2], Image:featured image1)

    Here is the code that i used:
    PHP Code:
    <div class="video_area">
      <h2 class="widgettitle">Latest Videos</h2>
      <?php global 
      
    $recentPosts = new WP_Query(); $recentPosts->query('showposts=3&cat=33');?>
      <ul class="video_list">
        <?php $i 1; while ($recentPosts->have_posts()) : $recentPosts->the_post(); ?>
        <li><a href="<?php the_permalink() ?>" rel="bookmark"><img src="/images/videoscreen<?php echo $i?>.png">
          <?php  short_title(); ?>
          </a></li>
        <?php $i++; endwhile; ?>
    <?php rewind_posts
    (); ?>
      </ul>
    </div>
    Now is working like this:

    Latest Videos Post (Proved Working Scenario)
    4. Best warm-up exercises3 (date: Jan 3, 2012, categories: [Videos, ExampleCat1], Image:featured image4) <-- This is not showing
    Instead Shows the following:
    3. Best warm-up exercises2 (date: Dec 20, 2011, categories: [Videos, ExampleCat1], Image:featured image3)
    2. Best warm-up exercises1 (date: Dec 5, 2011, categories: [Videos, ExampleCat1], Image:featured image2)
    1. Best warm-up exercises2 (date: Dec 20, 2011, categories: [Videos, ExampleCat1], Image:featured image3)

    In the dashboard the post are there, i used the wp reset loop (doesn't work) and wp version: 3.2.1, i try to reset the cache and also doesn't work either.

    Thanks in advance for any suggestion or hint.

  2. #2
    SitePoint Wizard bronze trophy chris.upjohn's Avatar
    Join Date
    Apr 2010
    Location
    Melbourne, AU
    Posts
    2,192
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    When using a custom post query in WordPress you need to always reset the loop back to it's original state otherwise it will continue to run the original loop, instead of using rewind_posts() use wp_reset_postdata()

  3. #3
    SitePoint Member
    Join Date
    Sep 2006
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hello, thanks for your replay, i try wp_reset_postdata() replacing the rewind_posts() and the problem still there.

  4. #4
    Mazel tov! bronze trophy kohoutek's Avatar
    Join Date
    Aug 2004
    Location
    Hamburg, Germany
    Posts
    4,248
    Mentioned
    30 Post(s)
    Tagged
    0 Thread(s)
    Shouldn't it be wp_reset_query()?
    Maleika E. A. | Rockatee | Twitter | Dribbble



  5. #5
    SitePoint Member
    Join Date
    Sep 2006
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you for your response @kohoutek.

    I also used the wp_reset_query() and still the same, also occurs with the default widget of recent posts, i disable the code and other plugins that in some way do the same as the code posted. The problem still there, i cannot disable all the plugins because i will lost the other widgets, if some knows a way i can disable all the plugins without losing the widgets when i restore them it would be great.

    Thanks all.


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •