Ask your WordPress questions! Pay money and get answers fast! (more info)

BBpress topic freshness function in wp_query. WordPress

  • SOLVED

Hello all,

I'm having trouble getting this function to run in with WP_Query: <?php bbp_author_link( array( 'post_id' => bbp_get_topic_last_active_id(), 'size' => 14 ) ); ?>

Here's my query:

<?php $topics_query = array(
'post_type' => bbp_get_topic_post_type(),
'posts_per_page' => 5,
'post_status' => array( bbp_get_public_status_id(), bbp_get_closed_status_id() ),
'ignore_sticky_posts' => true,
'no_found_rows' => true,
'meta_key' => '_bbp_last_active_time',
'orderby' => 'meta_value',
'order' => 'DESC',
); ?>
<?php $BB_Query = new WP_Query( $topics_query ); ?>

<?php if ( $BB_Query->have_posts() ) : ?>

<?php while ( $BB_Query->have_posts() ) : $BB_Query->the_post(); ?>

<?php bbp_author_link( array( 'post_id' => bbp_get_topic_last_active_id(), 'size' => 14 ) ); ?>
<a class="bbp-forum-title" href="<?php bbp_topic_permalink( $topic_id ); ?>"><?php bbp_topic_title( $topic_id ); ?></a>

</br>

<?php endwhile; ?>

<?php wp_reset_postdata(); ?>


I found [[LINK href="http://bbpress.org/forums/topic/wp_query-post-type-topic-help/"]]this bbress thread[[/LINK]] of someone having a similar problem. I swapped out bbp_get_topic_last_active_id() for a post id as said at the bottom and got an avatar to for that post so it most be bbp_get_topic_last_active_id().

I'm not sure what was meant by this though:

<blockquote>Or you could try

echo “bbp_get_topic_last_active_id() is “. bbp_get_topic_last_active_id() ;

to see what number that is producing at that point to know that it is doing something

if so, then you can try</blockquote>

[[LINK href="http://phpcrossref.com/xref/bbpress/_functions/bbp_get_topic_last_active_id.html"]]Here's bbp_get_topic_last_active_id code[[/LINK]]

Thank you for all of your help :D

Answers (3)

2014-09-12

timDesain Nanang answers:

You can try this code:

<?php
$topics_query = array(
'post_type' => bbp_get_topic_post_type(),
'posts_per_page' => 5,
'post_status' => array( bbp_get_public_status_id(), bbp_get_closed_status_id() ),
'ignore_sticky_posts' => true,
'no_found_rows' => true,
'meta_key' => '_bbp_last_active_time',
'orderby' => 'meta_value',
'order' => 'DESC',
);
$BB_Query = new WP_Query( $topics_query );
if ( $BB_Query->have_posts() ) :
?><ul><?php
while ( $BB_Query->have_posts() ) : $BB_Query->the_post(); ?>
<li>
<a class="bbp-forum-title" href="<?php bbp_topic_permalink(); ?>"><?php bbp_topic_title(); ?></a>
Started by: <?php bbp_author_link( array( 'post_id' => get_the_ID(), 'type' => 'avatar', 'size'=>32 ) ); ?>
Freshness by: <?php bbp_author_link( array( 'post_id' => get_post_meta( get_the_ID(), '_bbp_last_active_id', true ), 'type' => 'avatar', 'size'=>32 ) ); ?>
</li>
<?php
endwhile;
?></ul><?php
endif;
wp_reset_postdata();
?>


the output (screenshot):


timDesain Nanang comments:

or you can use <strong>bbp_get_topic_last_active_id</strong> instead of <em>get_post_meta</em>:

<li>
<a class="bbp-forum-title" href="<?php bbp_topic_permalink(); ?>"><?php bbp_topic_title(); ?></a>
Started by: <?php bbp_author_link( array( 'post_id' => get_the_ID(), 'type' => 'avatar', 'size'=>32 ) ); ?>
Freshness by: <?php bbp_author_link( array( 'post_id' => bbp_get_topic_last_active_id(get_the_ID()), 'type' => 'avatar', 'size'=>32 ) ); ?>
</li>


Chris comments:

Thank you, that worked!

2014-09-12

Navjot Singh answers:

Have you tried using [[LINK href="http://codex.bbpress.org/bbp_topic_author_link/"]]bbp_topic_author_link()[[/LINK]] instead of bbp_author_link()?

2014-09-12

Hariprasad Vijayan answers:

Hello,

Try
<?php bbp_author_link( array( 'post_id' => bbp_get_topic_last_active_id( $topic_id ), 'size' => 14 ) ); ?>
instead of
<?php bbp_author_link( array( 'post_id' => bbp_get_topic_last_active_id(), 'size' => 14 ) ); ?>
in your loop.