Support » Fixing WordPress » Inconsistent post return using WP_query

  • Resolved alexleonard

    (@alexleonard)


    I’m having a strange issue with inconsistent results from a new WP_query I’m using in my sidebar on a site in development.

    I’ve manually coded a couple of widgets to show 5 posts from 2 different categories. It works beautifully on everywhere on the site except for pages that call index.php or author.php as their template.

    I’m completely baffled as to this behaviour.

    I’ll give a couple of links first up.

    Check the following page and you’ll see that in the sidebar we have “Recent Releases” and then underneath that there’s “Upcoming Releases”.

    http://devel.invisibleagent.com/reviews/

    Now if you check the home page or an author page, the upcoming releases widget doesn’t display anything at all.

    http://devel.invisibleagent.com/
    http://devel.invisibleagent.com/artist/corrugated/

    I made sure to use WP_query over the normal query_posts as I thought this would be precisely the thing that avoided such issues.

    This is the code I’ve used for these widgets:

    <!-- BEGIN LATEST RELEASES WIDGET -->
    <?php
    $newReleases = new WP_query();
    $newReleases->query(array('showposts' => 5, 'orderby' => "date", 'cat' => 15, 'category__not_in' => array(126)));
    ?>
    <li class="widget widget-latest-releases"><h2 class="widgettitle">Latest Releases</h2>
    <?php while ($newReleases->have_posts()) : $newReleases->the_post(); ?>
    <div class="widget-release-cont">
    <a href="<?php the_permalink() ?>" rel="bookmark" title="Link to <?php the_title(); ?>"><?php $releasecover = get_post_meta($post->ID, "release-cover", true); if (!empty($releasecover)) {echo $releasecover;}?></a>
    <h3 class="post-title"><a href="<?php the_permalink() ?>" rel="bookmark" title="Link to <?php the_title(); ?>"><?php the_author_nickname(); ?></a></h3>
    <p class="widget-album-title"><a href="<?php the_permalink() ?>" rel="bookmark" title="Link to <?php the_title(); ?>"><?php the_title(); ?></a>
    
    </div><!-- end .widget-release-cont -->
    <?php endwhile; ?>
    </li>
    <!-- END LATEST RELEASES WIDGET -->
    
    <!-- BEGIN UPCOMING RELEASES WIDGET -->
    <?php
    $upcomingReleases = new WP_query();
    $upcomingReleases->query(array('showposts' => 5, 'orderby' => "date", 'cat' => 126));
    ?>
    <li class="widget widget-upcoming-releases"><h2 class="widgettitle">Upcoming Releases</h2>
    <?php while ($upcomingReleases->have_posts()) : $upcomingReleases->the_post(); ?>
    <div class="widget-release-cont">
    <?php $releasecover = get_post_meta($post->ID, "release-cover", true); if (!empty($releasecover)) {echo $releasecover;}?>
    <h3 class="post-title"><?php the_author_nickname(); ?></h3>
    <p class="widget-album-title"><?php the_title(); ?>
    
    </div><!-- end .widget-release-cont -->
    <?php endwhile; ?>
    </li>
    <!-- END UPCOMING RELEASES WIDGET -->

    I’ve tried randomly adding in rewind_posts() and update_post_caches($posts) but I’m really not familiar with their usage so might not have done the right thing.

    So yeah, I’m feeling a little confused as to what is going wrong here, and why it’s only happening on the index.php and author.php templates, but not on anything else on the site.

    I’ve tried stripping out all code from index.php to see if it makes a difference, but I still have the same issue.

    Any suggestions very welcome.

Viewing 1 replies (of 1 total)
  • Well, I feel a little stupid but I finally worked out what the hell was going on.

    I had ACE Category Excluder installed to prevent the “Upcoming Release” posts from showing up in the feed. I only just noticed now that this was also the cause of these posts not appearing in the sidebar.

    Ooops..

Viewing 1 replies (of 1 total)
  • The topic ‘Inconsistent post return using WP_query’ is closed to new replies.