Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm trying to get the ID of a post in the first loop (using <?php $postid = get_the_ID(); ?> ) and use it in a variable ($postid) to exclude that very post from a second loop (using post__not_in):

 <?php

/**
 * Replies Loop
 *
 * @package bbPress
 * @subpackage Theme
 */

?>

            <?php if ( ! get_query_var( 'paged' ) ) : ?>

                <?php
                    $args = array(
                        'post_type' => 'bbp_reply',
                        'posts_per_page' => '1',
                        'paged' => '2',
                        'post_parent' => $post->ID,
                        'gdsr_sort' => 'thumbs',
                        'gdsr_ftvmin' => '1',
                        'gdsr_order' => 'desc'
                    );
                ?>
                <?php query_posts( $args ); ?>
                <?php while ( have_posts() ) : the_post(); ?>

                    <div class="most-voted">
                        <h2><?php  the_title(); ?></h2>
                        <?php the_content(); ?>
                        <?php bbp_reply_admin_links(); ?>
                    </div>

                    <?php $postid = get_the_ID(); // capture the id ?>

                <?php endwhile; ?>
                <?php wp_reset_query(); ?>

                <p>________________</p>

            <?php endif; ?>



<?php
    $default = array(
        'post__not_in' => $postid
    );
?>

<?php if ( bbp_has_replies( $default ) ) : ?>

    <?php get_template_part( 'pagination', 'bbp_replies' ); ?>


            <?php while ( bbp_replies() ) : bbp_the_reply(); ?>

                <div class="topic-entry">

                    <div class="topic-author">
                        <?php bbp_reply_author_link( array( 'type' => 'avatar' ) ); ?>
                        <?php bbp_reply_author_link( array( 'type' => 'name' ) ); ?>
                        <?php printf( __( '%1$s', 'bbpress' ), get_the_date() ); ?>
                    </div>

                    <div class="topic-content">
                        <?php bbp_reply_content(); ?>
                        <span class="like-counter"><?php DisplayVotes(get_the_ID()); ?></span>
                    </div>

                    <?php wp_gdsr_render_article_thumbs(); ?>

                    <?php bbp_reply_admin_links(); ?>

                </div>

            <?php endwhile; ?>

<?php endif; ?>

But for some reason I'm getting this error:

Warning: array_map(): Argument #2 should be an array in /home/alex/www/taiwantalk/wp-includes/query.php on line 2104 Warning: implode(): Invalid arguments passed in /home/alex/www/taiwantalk/wp-includes/query.php on line 2104 
share|improve this question
    
This is pretty much the same question as your previous one: wordpress.stackexchange.com/questions/13143/… –  anu Mar 27 '11 at 10:21
add comment

1 Answer

up vote 1 down vote accepted

post__not_in accepts an array so change

 <?php $postid = get_the_ID(); // capture the id ?>

to

 <?php $postid[] = get_the_ID(); // capture the id ?>

and you'll be fine.

share|improve this answer
    
thanks that did it! One more thing, how can I echo that array? –  janoChen Mar 27 '11 at 10:00
    
How can I use that array in the 'post__not_in'? –  janoChen Mar 27 '11 at 10:16
    
Never mind it works. Thanks again. –  janoChen Mar 27 '11 at 10:33
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.