Horje
BBpress topic freshness function in wp_query. - Wordpress Solution
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 rel="nofollow" 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:
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
[[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

Solution - 1

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 rel="nofollow" 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):


Solution - 2

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


Solution - 3

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.





Wordpress

Related
List all posts with 2 terms of a taxonomy - Wordpress Solution List all posts with 2 terms of a taxonomy - Wordpress Solution
Table fix - Wordpress Solution Table fix - Wordpress Solution
Merging Terms with Bootstrap Carousel - Wordpress Solution Merging Terms with Bootstrap Carousel - Wordpress Solution
Use the menu from one theme for another (price question) - Wordpress Solution Use the menu from one theme for another (price question) - Wordpress Solution
Need HTML / PHP converted into Echo - Wordpress Solution Need HTML / PHP converted into Echo - Wordpress Solution

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
7