Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

For some strange reason this code works perfect on my local installation of Wordpress yet when I put it live on a web server the code just repeats the same two articles over and over again and doesn't progress beyond the same two articles. I'm using InfiniteScroll (not the WP plugin, my manual installation of it). Is there anything wrong with my loop?

EDIT

Here's the link to code in full taken from single.php: http://pastebin.com/dtiSHUYP

<div id="post-wrap">


                <?php // Show all posts within this category
                $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
                $args= array(
                    'category_name' => $cat->slug, 
                    'paged' => $paged,
                    'cat' => '-12',
                    'posts_per_page' => 2,
                    'post__not_in' => array( $post->ID )
                );
                query_posts($args); ?>

                <?php $current_post_date = $post->post_date; ?>

                <?php if( have_posts() ) : while ( have_posts() ) : the_post(); ?>

                <?php if ($post->post_date < $current_post_date) {  ?>

                <article>
                    <figure>

                      <?php
                          $image_link=get_post_meta($post->ID,'Image_Link',true);
                          if($image_link != '') {
                          echo '<a href="http://example.com">'. get_the_post_thumbnail() .'</a>';
                          } else {
                          echo get_the_post_thumbnail();
                          }
                      ?>

                      <figcaption>
                            <?php
                            // Call in the contents of a custom field called Credit and if custom field in admin panel is empty don't display <p> tags otherwise wrap contents of custom field in <p> tags
                            $credit=get_post_meta($post->ID,'Credit',true);
                            if($credit != '') {
                            echo '<p>'. $credit .'</p>';
                            } else {
                            echo ' ';
                            }
                            ?>
                      </figcaption>
                    </figure>

                    <?php
                    $sub_title=get_post_meta($post->ID,'subtitle',true);
                    if($sub_title != '') {
                    echo '<h1>'. get_the_title() .'<span> / '. $sub_title . ' / ' . get_the_time('l jS F') .'</span></h1>';
                    } else {
                    echo '<h1>'. get_the_title() .'<span> / ' . get_the_time('l jS F') .'</span></h1>';
                    }
                    ?>

                    <?php the_content(''); ?>

                    <div class="a-options">
                        <a href="#post-<?php the_ID(); ?>" class="comments scrollto">Comment</a>

                        <!-- share -->
                        <div class="share-button">
                            <div class="buttons">
                                <div class="facebook">                          

                                    <div class="fb-like" data-send="false" data-layout="button_count" data-width="450" data-show-faces="false" data-font="arial"></div>

                                </div>

                                <div class="twitter">

                                    <a href="https://twitter.com/share" class="twitter-share-button" data-text="<?php the_title(); ?>" data-url="<?php the_permalink(); ?>" data-via="kettlesyard" data-related="kettlesyard" data-hashtags="kettlesyard">Tweet</a>
                                    <script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>

                                </div>

                                <div class="pinterest">
                                    <a href="http://pinterest.com/pin/create/button/?url=<?php the_permalink(); ?>" class="pin-it-button" count-layout="horizontal"><img border="0" src="//assets.pinterest.com/images/PinExt.png" title="Pin It" /></a>
                                </div>

                            </div>

                            <span class="pseudo-button">&#043; Share</span>
                         </div> <!--! /share -->

                    </div><!--! /a-options -->


                    <?php if ( in_category( 'contact' ) ) : // Display nothing ?>

                        <?php // Else, show comments
                        else : ?>

                            <?php global $withcomments;
                            $withcomments = 1;
                            comments_template(); ?>

                    <?php endif; ?>

                  </article>

                  <?php } ?>




                <?php endwhile; ?>



                <div id="next-prev-wrap" class="nextprev"><?php next_posts_link(); ?> <?php previous_posts_link(); ?></div>




                <?php endif;  wp_reset_query(); ?>

                </div>
share|improve this question
add comment

1 Answer 1

Your first issue is the fact that you're using query_posts. That function isn't meant for creating new queries to the database; instead, it's used to modify the existing global query.

Read up here and here for more information on what you can use instead.

Second, there is just some strange code in your template that, honestly, shouldn't have worked in the first place. This line:

$args= array(
    'category_name' => $cat->slug, 
    'paged' => $paged,
    'cat' => '-12',
    'posts_per_page' => 2,
    'post__not_in' => array( $post->ID )
);

... is referencing variables that I don't see elsewhere in your code. Namely, $cat and $post. The fact that you're referencing $post at all tells me you either have some other query higher up in the page, or are inside another loop ... in either case, calling query_posts() will definitely hurt.

Also, the minute differences between your local installation and network installation can also play a part. If you aren't using the exact same versions of WP, PHP, MySQL, etc across both systems, strange differences like this can crop up.

share|improve this answer
    
Yeah I have another loop above it that outputs the content from the current post. Shall I link you up to my full code? Would that help? –  egr103 Jul 9 '12 at 22:34
    
Please always link to the full code. –  EAMann Jul 9 '12 at 22:40
    
Here's the link to the code in full: pastebin.com/dtiSHUYP Its also added to the post –  egr103 Jul 10 '12 at 17:31
    
Any ideas @EAMann? –  egr103 Jul 11 '12 at 15:14
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.