0

我有一个独特的情况,我需要为 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>
4

1 回答 1

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' => '',
); ?>
于 2013-06-19T07:53:35.323 回答