Forums

[resolved] Missing $comment_post_ID on template page (8 posts)

  1. Sky_walker
    Member
    Posted 6 months ago #

    I'm trying to get working comments of my custom page using php scripted template (which do some math calculations).

    Somehow I managed to make it work for a moment, but by editing my script more and more I've crashed comments to the point where I have no idea how to fix it.
    The problem is very simple - in comments part of page I have:

    <!-- commenting_data -->
    <p><textarea name="comment" id="comment_text" tabindex="4"></textarea></p>
    
    <p><input name="submit" type="submit" id="submit" tabindex="5" value="Submit Comment" />
    <input type='hidden' name='comment_post_ID' value='' id='comment_post_ID' />
    <input type='hidden' name='comment_parent' id='comment_parent' value='0' />

    - so the value of comment_post_ID is missing.
    I have no idea how to set it up, or how it got removed - especially because I don't use variable $comment_post_ID anywhere in my script, nor am manipulating the $_POST data.

    The php code in wp-comments-post.php throws an error in this part of code:

    if ( empty($status->comment_status) ) {
    	do_action('comment_id_not_found', $comment_post_ID);
            echo "comment_id_not_found";
            exit;
    }

    (added echo instruction to find out an error)

    Anyone might have an idea how to restore comment_post_ID? Or how to set it up again, or how to bypass the problem?

  2. lhoylhoy
    Member
    Posted 6 months ago #

    the value should be <?php echo $id; ?>

  3. Sky_walker
    Member
    Posted 6 months ago #

    it's empty... after setting it to ID of my post I had Invalid Data: Please go back and try again. error.
    So... WP Captcha Free is spoiling the code now.
    Any ideas how to fix it without disabling the plugin?

    The list of plugins I have (might help?) :

    Collapsing Categories 0.6.3
    Evermore 2.2
    Get Recent Comments 2.0.5
    Google Analytics for WordPress 2.9.1
    List Subpages 1.0
    My Custom Widgets 1.8.1
    Robots Meta 3.0.11
    Subscribe To Comments 2.1.2
    WP-PostRatings 1.40
    WP Captcha Free 0.5

    BTW, should $id be set to page ID or not? I got confused a bit.

  4. sirozz
    Member
    Posted 6 months ago #

    Exactly the same for me. The function "comment_id_fields()" return always an empty value for the field comment_post_ID.

  5. sirozz
    Member
    Posted 6 months ago #

    Resolved. Check the call of comments_template(), it must be inside the post loop to work properly:

    while ( have_posts() ) { must be here }

  6. Sky_walker
    Member
    Posted 6 months ago #

    Well - it wasn't entirely true for me.
    But the idea was great :D

    Here is the code I used to put Comments into my fully customized template page:

    <div>Here is the template</div>
    
    <?php if (have_posts()) : while (have_posts()) : the_post();  comments_template();  endwhile; endif; ?>
    
    <div>and here is the stuff after the template</div>
  7. preaxz
    Member
    Posted 2 months ago #

    I recently have the same error and found this page.
    I find the problem was not the loop, you can put the comment form anywhere you like but remember to put the_post(); somewhere before your form. Usually right after if ( comments_open() ) :

    so it become

    <?php if ( comments_open() ) : the_post(); ?>
    Your form
    <?php endif; ?>
  8. clickit
    Member
    Posted 1 week ago #

    preaxz, you are a star my friend.
    I was experiencing the white screen of death with comments on a template page after submitting the form. You're solution seems to work just fine.

Reply

You must log in to post.

About this Topic