I’m having a problem whereby each time I post a test comment, it is always being saved to the very first post.
The code below is taken from the ‘single.php’. In the first chunk, I want to retrieve the latest post. Then in the second chunk, I want to show a list of the 5 most recent blogs excluding the most recent (already displaying on the page).
I have tried resetting the $post variable by assigning it to a temporary variable before the ‘foreach’ loop. I also used ‘wp_reset_postdata’… but the problem still occurs.
The code for the latest post:
<?php if (have_posts()) :
while (have_posts()) : the_post();
global $more;
$more = 1;
?>
The code for the 5 most recent posts (excluding that already displayed):
I used an echo statement to check the value of the $post and it returns the correct number, so I think that the variable is being reset correctly, but somehow the comments are being sent to the wrong place?
<?php echo '<p>'.get_the_ID().'</p>'; ?>
^Shows the correct post number
– deactivating all plugins to see if this resolves the problem. If this works, re-activate the plugins one by one until you find the problematic plugin(s).
– switching to the Twenty Eleven theme to rule out any theme-specific problems.
– resetting the plugins folder by FTP or PhpMyAdmin. Sometimes, an apparently inactive plugin can still cause problems.
Viewing 1 replies (of 1 total)
The topic ‘Comments being saved to wrong post… wp_reset_postdata?’ is closed to new replies.
(@aneemal)
12 years, 3 months ago
Hi all,
I’m having a problem whereby each time I post a test comment, it is always being saved to the very first post.
The code below is taken from the ‘single.php’. In the first chunk, I want to retrieve the latest post. Then in the second chunk, I want to show a list of the 5 most recent blogs excluding the most recent (already displaying on the page).
I have tried resetting the $post variable by assigning it to a temporary variable before the ‘foreach’ loop. I also used ‘wp_reset_postdata’… but the problem still occurs.
The code for the latest post:
The code for the 5 most recent posts (excluding that already displayed):
Then I include the comments:
I used an echo statement to check the value of the $post and it returns the correct number, so I think that the variable is being reset correctly, but somehow the comments are being sent to the wrong place?
<?php echo '<p>'.get_the_ID().'</p>'; ?>
^Shows the correct post number
Anyone have any ideas, or advice?
Many thanks in advance