The Support Forums will be in read-only mode for a scheduled maintenance window on 01 September 2016 14:00 UTC - 20:00 UTC. More information.

Updating $wp_query inside the Loop (1 post)

  1. admreg
    Posted 7 years ago #

    Hi everybody,

    I am trying to dynamically add/remove comments before displaying them. In comments.php, I have:

    $comment_id = wp_insert_comment( $commentdata );
    /* end of my code */
    /*beginning of original theme code*/

    The problem is that the newly added comment is not displayed until page refresh. I figure this is because the Loop works with cached comments stored in $wp_query. What is the best way to update the comment cache while keeping all the Loop counters intact? I would like to have a piece of code that can be just pasted into any theme without interfering with its original comment code. Performance is an issue, too.

Topic Closed

This topic has been closed to new replies.

About this Topic