• Resolved wozzyozzy

    (@wozzyozzy)


    I’ve been having an odd issue with the_content() and the_excerpt() calls inside the Loop. As soon as either of these methods are called, any subsequent calls relating to the post (e.g. the_permalink(), edit_post_link()) all point to a single incorrect post.

    Its as if these methods are altering the loop, and resetting the references to the first post in my only category (other than Uncategorized).

    Has anyone encountered such behavior?

    Loop code below, perhaps I’m doing something bizarre, as I’m new to WordPress. The symptom with the code below is that information in the “postmetadata” paragraph is correct, but the “Read More” link after the_excerpt() points to a completely different post (and always the same post).

    <?php if (have_posts()) : ?>
    		<?php while (have_posts()) : the_post(); ?>
    
    			<div <?php post_class() ?> id="post-<?php the_ID(); ?>">
    
    				<h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
    
    <p class="postmetadata">
    	<span class="metaEntry"><abbr class="published" title="<?php the_time(__('l, F jS, Y, g:i a', 'example')); ?>"><?php the_time(__('F j, Y', 'example')); ?></abbr></span><span class="delim">|</span>
    	<span class="metaEntry"><?php the_tags('Tags: ', ', ', '<br />'); ?> Posted in <?php the_category(', ') ?></span><span class="delim">|</span>
    	<?php edit_post_link('Edit', '<span class="metaEntry">', '</span><span class="delim">|</span>'); ?>
    	<span class="metaEntry"><?php comments_popup_link('No Comments »', '1 Comment »', '% Comments »'); ?></span>
    </p>
    
    				<div class="entry">
    					<?php the_excerpt(); ?><a href="<?php the_permalink() ?>">Read more »</a>
    				</div>
    			</div>
    
    		<?php endwhile; ?>
    
    		<div class="navigation">
    			<div class="alignleft"><?php next_posts_link('&laquo; Older Entries') ?></div>
    			<div class="alignright"><?php previous_posts_link('Newer Entries &raquo;') ?></div>
    		</div>
    
    	<?php else : ?>
    
    		<h2 class="center">Not Found</h2>
    		<p class="center">Sorry, but you are looking for something that isn't here.</p>
    		<?php get_search_form(); ?>
    
    	<?php endif; ?>

Viewing 3 replies - 1 through 3 (of 3 total)
  • Works okay when I replace the loop in wp-content/themes/default/index.php with your loop.

    Might make sure you don’t have a plugin causing the problem. Might also update your permalink structure.

    Thread Starter wozzyozzy

    (@wozzyozzy)

    Thanks Michael!

    I did a step by step deactivation, and it looks like there’s a conflict with a custom widget that uses its own loop. Perhaps there’s a variable naming conflict between the two.

    I’ll look into a fix or the proper way to implement multiple loops, but the custom widget uses the following loop which appears to cause the conflict.

    Thanks for the help I’ll investigate further in hopes of a solution that resolves the conflict.

    `
    <?php $latest = new WP_Query($postsQuery); ?>

    <?php if( $latest->have_posts() ) : while( $latest->have_posts() ) : $latest->the_post() ?>

    //dostuff

    <?php endwhile; endif; ?>
    `

    Thread Starter wozzyozzy

    (@wozzyozzy)

    Well the issue definitely appears to be an issue with using multiple loops. As mentioned above I was trying to spool up a new loop to do some post filtering, however this loop was somehow being executed in a way that affected how the_content and the_excerpt work.

    As my primary requirement was to find posts of a certain category with specific meta data values, my solution was as follows:

    ?php foreach(get_posts('category='.get_cat_id('Tournaments')) as $postEntry) : ?>
    
    <?php
    $id = $postEntry->ID;
    //Do some meta data filtering using get_post_meta($id,'MyMeta',true);
    ?>
    
    <?php endforeach; ?>

    This seems to avoid the conflict with the Loop in the main template. This custom widget is also my own custom code implemented using MyCustomWidget 1.8.1 and since this plugin uses eval() to execute custom code it may be a scoping issue of some sort.

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

The topic ‘the_content() alters post reference in the Loop’ is closed to new replies.