I'm using bbPress. I'm in a single page of the custom post type bbp_topic. As you can imagine this custom post type stores another custom post type called bbp_reply. I'm using the following query to list the most voted replies at the top (like Youtube), helped by the GD start rating plugin:

        <?php $custom_posts = new WP_Query(); ?>
        <?php $custom_posts->query('gdsr_sort=thumbs&post_type=bbp_reply&posts_per_page=2'); ?>
        <?php while ($custom_posts->have_posts()) : $custom_posts->the_post(); ?>
            <div class="content-block-2">
                <a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'twentyten' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php the_title(); ?></a>
            <?php the_content(); ?>
        <?php endwhile; ?>

The problem is that the query is listing all the replies from all the bbp_topic custom post type. I need to query something like this: list all the custom post types bbp_reply from this single bbp_topic custom post type you are viewing right now.

(I know how to get the ID of the current bbp_topic custom post type: $post->ID but I'm not very sure how to use it).

Any suggestions?


It appears the topic of a reply is stored in the _bbp_topic_id meta field. Older versions stored this in the post_parent field, but it seems this is deprecated? So you can add '&meta_key=_bbf_topic_id&meta_value=' . $post-ID to your query to get only replies to this topic.

| improve this answer | |
  • @Jan Fabry Yes, post_parent=' . $post-ID did it. – janoChen Mar 24 '11 at 9:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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