Skip to:
Content
Pages
Categories
Search
Top
Bottom

Reply To: How to add latest reply or topic to forum list

@jimmmy

Participant

update: this was undesirable because the link to the reply was going to the reply itself, which is just a single post of the ‘reply’ custom post type. I have created this dodgy hack of the above code so the permalink for the replies is still the topic permalink. I’m sure there are a million better ways to do this, but it does the job for me so i thought i’d share the updated version.

function jag_add_last_reply() { { 
 $jag_last_reply_id = bbp_get_forum_last_reply_id();
 $jag_last_topic_id = bbp_get_forum_last_topic_id();

$new_args = array(
    'post_type'=> 'reply',
    'p' => $jag_last_reply_id
);
$post_title_args = array(
    'post_type'=> 'topic',
    'p' => $jag_last_topic_id
);
$other_args = array(
    'post_type'=> 'topic',
    'p' => $jag_last_topic_id
);
$jag_query = new WP_Query( $post_title_args );
$nest_query = new WP_Query( $new_args );
$another_nest_query = new WP_Query( $other_args );

   if ( $jag_query->have_posts() ) : while ( $jag_query->have_posts() ) : $jag_query->the_post();
     $this_post_id=$post->ID;
     $this_post_permalink= get_permalink(); ?>   
                             
     <a href="<?php echo $this_post_permalink; ?>">

<?php endwhile; 
   endif; wp_reset_query();

   if ( $nest_query->have_posts() ) : while ( $nest_query->have_posts() ) : $nest_query->the_post();
     $this_post_id=$post->ID;
     $this_post_title= get_the_title();
     $this_post_content= get_the_excerpt(); ?>
                             
     <h1><?php echo $this_post_title; ?></h1></a>
     <div class="the_content"><?php echo $this_post_content; ?></div>
                     
   <?php endwhile;
elseif ( $another_nest_query->have_posts() ) : while ( $another_nest_query->have_posts() ) : $another_nest_query->the_post();
     $this_post_id=$post->ID;
     $this_post_title= get_the_title();
     $this_post_content= get_the_excerpt(); ?>   
                             
     <h1><?php echo $this_post_title; ?></h1></a>
     <div class="the_content"><?php echo $this_post_content; ?></div>
                     
   <?php endwhile; 
   endif; 
    }} 
// Hook into action
add_action('bbp_theme_after_forum_description','jag_add_last_reply');
Skip to toolbar