wordpress:在其他帖子的单个帖子上显示评论时遇到问题

时间:2012-09-07 09:40:20

标签: wordpress comments

我有一个独特的情况,我需要为3个不同的帖子显示相同的评论。这3个不同的帖子显然在DB中链接在一起。所以我需要做的是强制使用1个帖子ID为所有语言提交评论并检索它...而不是使用3个差异ID我需要使用1并坚持下去。

我有$ current_post_duplicate_id,所有3个翻译的帖子都是9。

如果我对原始post_ID 9的原始帖子提交评论一切正常,我会看到评论并且会被提交。但是,当我切换到翻译版本时,没有显示任何内容,但我强迫get_comments使用id 9来显示并通过$ current_post_duplicate_id提交评论,那么发生了什么?为什么这不起作用?

我无法弄清楚发生了什么,我想这里的一位大师可以给我一个提示。

<?php
//Uniting comments in all languages by setting default language for comments en in this case
$current_post_duplicate_id = icl_object_id (get_queried_object_id(), 'tribe_events', false, 'en');
?>






                            <div id="eventattend">

                                  <?php if ('open' == $post->comment_status) : ?> 
                                    <span><?php _e('Are you intersted?'); ?></span>



                                    <?php if ( $user_ID ) : ?>


<?php
  $usercomment = get_comments( array( 'user_id' => $current_user->ID, 'post_id' => $current_post_duplicate_id ) );
  if ( 1 <= count( $usercomment ) ) {
?>
                                              <form method="post" action="">
                                                  <a class="eventno" href="javascript:;" onclick="parentNode.submit();"><?php _e('No'); ?></a>
                                                  <input type="hidden" name="delmycom" value="1" />

                                                  <?php
                                                    //
                                                    $delete_my_event_interest = $_POST['delmycom'];
                                                      //
                                                      if ( isset ($delete_my_event_interest) ) {

                                                            $current_user_comment = get_comments( array(
                                                              'post_id' => $current_post_duplicate_id,
                                                              'user_id' => get_current_user_id(),
                                                              'number' => 1,
                                                              'status' => 'approve',
                                                              'type' => 'comment'
                                                            ) );

                                                        wp_delete_comment( $current_user_comment[0]->comment_ID );
                                                      }
                                                      //
                                                  ?>
                                              </form>
<?php } else { ?>
                                              <form action="<?php echo get_option('siteurl'); ?>/wp-comments-post.php" method="post">
                                                  <?php comment_id_fields(); ?>
                                                  <?php do_action('comment_form', $current_post_duplicate_id); ?>
                                                  <input type="hidden" name="comment" value="I'm attending this Event!" />
                                                  <a class="eventyes" href="javascript:;" onclick="parentNode.submit();"><?php _e('Yes'); ?></a>
                                              </form>
<?php } ?>


                                    <?php else : ?>
                                      <a class="eventyes loginosx" href="#"><?php _e('Yes'); ?></a>
                                      <?php _e('*You need to be loged in to say YES.'); ?>
                                    <?php endif; ?>





                                  <?php endif; // if you delete this the sky will fall on your head ?>

                                  <div class="clearfloat"></div><!-- Very Important -->
                            <!-- End #eventattend --></div>



                    <!-- End #eventsingle --></div>










                    <ul class="sidebarlists" id="interestedlist">
                        <li>
                        <h2><?php _e('Who\'s interested so far?'); ?> (<?php comments_number( '0', '1', '%' ); ?>)</h2>
                        <ul>

                                  <?php

                                    $recent_comments = get_comments( array(
                                      'post_id' => $current_post_duplicate_id,
                                      'number' => 25,
                                      'status' => 'approve',
                                      'type' => 'comment',
                                      'order' => 'ASC'
                                    ) );

                                    foreach ($recent_comments as $comment) {
                                  ?>
                                      <li id="attendee-<?php echo $comment->comment_ID; ?>">
                                          <a href="#"><?php echo get_avatar( $comment->comment_author_email, $size = '50', $alt = $comment->comment_author.' is attending this event' ); ?></a>
                                          <span><?php echo $comment->comment_author; ?></span>
                                      </li>
                                  <?php
                                    }
                                  ?>

                        </ul>
                        </li>
                    <!-- End #sidebarlists --></ul>

1 个答案:

答案 0 :(得分:0)

使用此

<?php $comments = get_comments(array('post_id' => 1)); ?>

您还可以传递以下参数

<?php $defaults = array(
    'author_email' => '',
    'ID' => '',
    'karma' => '',
    'number' => '',
    'offset' => '',
    'orderby' => '',
    'order' => 'DESC',
    'parent' => '',
    'post_id' => 0,
    'post_author' => '',
    'post_name' => '',
    'post_parent' => '',
    'post_status' => '',
    'post_type' => '',
    'status' => '',
    'type' => '',
    'user_id' => '',
    'search' => '',
    'count' => false,
    'meta_key' => '',
    'meta_value' => '',
    'meta_query' => '',
); ?>