• I made a custom comment template and calling it in a page. the function comment_form($arg,$id) is not working. it this function by $id i am passing post id on which i want to comment but when i click on submit button the comment was not done on that post. it save comment on the other post. the function getting the id of page from url. please help me.

    <?php
    
    	if (!empty($_SERVER['SCRIPT_FILENAME']) && 'month_comment3.php' == basename($_SERVER['SCRIPT_FILENAME']))
    		die ('Please do not load this page directly. Thanks!');
    
    	if ( post_password_required() ) { ?>
    		This post is password protected. Enter the password to view comments.
    	<?php
    		return;
    	}
    ?>
    
    <?php // Posts per page setting
    $ppp = get_option('posts_per_page'); // either use the WordPress global Posts per page setting or set a custom one like $ppp = 10;
    $custom_offset = 5; // If you are dealing with your custom pagination, then you can calculate the value of this offset using a formula
    $arg = array(
      'orderby' => 'name',
      'parent' => 0,
      'order' => 'DESC',
      'number' => '3',
      );
    $taxonomies=get_terms('monthly_statement_category', $arg);$i=1;
    
    foreach ( $taxonomies as $taxonomy ) {
     $val1=$taxonomies[0]->name;
     $val2=$taxonomies[1]->name;
     $val3=$taxonomies[2]->name;
    
     }
    
    $args3=array(
      'monthly_statement_category'=>$val3,
      'post_type' => 'monthly_statement',
      'post_status' => 'publish',
      'order' => 'DESC',
    
    );
    $my_query = null;
    $my_query = new WP_Query($args3);
    $p=1;
    if( $my_query->have_posts() ) { $my_query->the_post();
    $id =get_the_ID(); $p++; wp_reset_query(); } else "no";
    echo $id;
    
    $sql = "SELECT comment_ID, comment_author, comment_date, comment_content, comment_post_ID
     FROM {$wpdb->comments} WHERE
     comment_post_ID ='".$id."' AND comment_approved = 1
     ORDER by comment_ID DESC LIMIT 0 , 10 ";
    
    $comments_list = $wpdb->get_results( $sql );
    
    if ( count( $comments_list ) > 0 ) {
     $date_format = get_option( 'date_format' );
    
     foreach ( $comments_list as $comment ) { ?>
     <div class="media">
     <a class="pull-left" href="#"><img class="media-object" src="<?php bloginfo('stylesheet_directory'); ?>/bootstrap/img/6464.png"> </a>
     <div class="media-body">
                            <h4 class="media-heading"><?php echo $comment->comment_author; ?></h4><p><?php echo substr( $comment->comment_content, 0, 50 );?></p></div>
                        </div>
     <?php } ?>
     <hr>
                        <div class="pagination">
    
       <?php echo paginate(); ?>
    
        </div>
        <hr> <?php
    
    } else {
     echo '<p>No comments</p>';
    }
    ?>
    
    <div class="row-fluid">
    <?php
    $args = array(
      'fields'               => apply_filters( 'comment_form_default_fields', $fields ),
    		'comment_field'        => '<div class="span8"><label for="comment">' . _x( 'Comment', 'noun' ) . '</label><textarea id="comment" class="span12" name="comment" cols="58" rows="5" aria-required="true"></textarea>',
    		'must_log_in'          =>  sprintf( __( 'You must be <a href="%s">logged in</a> to post a comment.' ), wp_login_url( apply_filters( 'the_permalink', get_permalink( $post_id ) ) ) ) . '</p>',
    		'logged_in_as'         =>  sprintf( __( 'Logged in as <a href="%1$s">%2$s</a>. <a href="%3$s" title="Log out of this account">Log out?</a>' ), admin_url( 'profile.php' ), $user_identity, wp_logout_url( apply_filters( 'the_permalink', get_permalink( $post_id ) ) ) ) . '</div>',
    
    		'id_form'              => 'commentform',
    		'id_submit'            => 'submit',
    		'title_reply'          => __( 'Leave a Reply' ),
    		'title_reply_to'       => __( 'Leave a Reply to %s' ),
    		'cancel_reply_link'    => __( 'Cancel reply' ),
    		'label_submit'         => __( 'Send Message' ),
    
      'fields' => apply_filters( 'comment_form_default_fields', array(
    
     'author' => '<div class="span4"><label for="author">Name</label>
    		            <input id="author" class="span12" name="author" type="text" value="" />',
    		'email'  => '<label for="email">Email</label>
    		            <input id="email" class="span12" name="email" type="text" size="5" value="" /></div>',
    
        )
      ),
    );
    echo $id;
    comment_form($args,$id);
    ?>
    </div></div>

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter Prateek28dueby89

    (@prateek28dueby89)

    url of page is http://localhost/Prateek/Trade/?page_id=39

    the var id getting page id not post id

    Thread Starter Prateek28dueby89

    (@prateek28dueby89)

    either comment form is not display or if it display comment form than the comment is saving on the post which have id 39. not for correct post

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Comment form() is not working’ is closed to new replies.