WordPress.org

Ready to get started?Download WordPress

Forums

Funny comments error, mismatching with the right article (7 posts)

  1. Carlo Rizzante
    Member
    Posted 2 years ago #

    Hi!
    I get a weird, funny effect with the comments at the bottom of my articles. Time to time no comments appear, even if they're supposed to, or instead, comments of an other articles take place.

    Basically I've to refresh, and the second time I do, finally I get the right comments matching the right article.

    Obviously this causes trouble to visitors.

    My website: http://carlorizzante.com

    Any idea, please?

    Thanks in advance, ciao!
    Carlo

  2. alchymyth
    Forum Moderator
    Posted 2 years ago #

    it is possible, that the code for the 'Articles on similar topics' section does not restore the query_string properly;

    try to add wp_reset_query(); after this code, or before the comment section.

    http://codex.wordpress.org/Function_Reference/wp_reset_query

  3. Carlo Rizzante
    Member
    Posted 2 years ago #

    It makes sense and it's probably the problem. I added wp_reset_query(); but with no luck.

    This the part of the code that fetches the query.

    $rand_posts = get_posts( $query_args );
    wp_reset_query();

    Is it the wrong way to operate a query beside the main loop?

    Also, I keep the comments outside the loop, after endwhile;

    If I skip the whole code for listing similar post, the comments are just fine.

    Thanks for your help, ciao!

  4. Carlo Rizzante
    Member
    Posted 2 years ago #

    Well, I omitted the arguments I pass to the query, but I guess it's not the critical point. Anyway the whole function to fetch similar posts is published here:
    http://carlorizzante.com/2011/08/list-similar-posts-a-very-simple-functionality-plugin-for-wordpress/
    ...and sure thing I would like it to work with no trouble for who eventually decides to implement it.

  5. alchymyth
    Forum Moderator
    Posted 2 years ago #

    try and save the $post object into a $temp variable before your get_posts code, and restore it at the end:

    change line12 of your function code in your srticle to:
    global $post; $temp = $post;

    change line85 of your function to:

    $post = $temp; }

  6. Carlo Rizzante
    Member
    Posted 2 years ago #

    Hi again!
    I tried with the suggestion,

    $post = $temp and then $temp = $post, with no success. I tried adding wp_reset_query(); and wp_reset_postdata();.

    Nothing... the comments still got messy. All the above were superfluous, since the problem was here:

    foreach( $posts_lot as $post ) { ...

    So now is something like:
    foreach( $posts_lot as $post2 ) { ...
    ...I still have to decide how to call it.

    And it works fine. For now :D

    Thanks for the support, anyway! Ciao!

  7. Ron Kellen
    Member
    Posted 2 years ago #

    We are getting a similar experience with our blogs. I'm getting all kinds of weird comments about our commercial blog as if we were replying to the blogs of others, but we are certainly not doing that. We are simply posting blogs.

    Is this an issue sitewide?

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags