Skip to:
Content
Pages
Categories
Search
Top
Bottom

WP_Query post type topic help


  • hitkid
    Participant

    @hitkid

    Hello all,

    I am trying to add bbpress functions such as bbp_get_topic author and so on.

    <?php
    			$args = array( 'post_type' => 'topic', 'posts_per_page' => 10 );
    			$loop = new WP_Query( $args );
    			while ( $loop->have_posts() ) : $loop->the_post();
    				the_title();
    				bbp_get_topic_author_link ( array( 'size' => '60' )  );
    			endwhile;
    			?>

    I can get the_title(); and the_content(); but am having problems with getting this in:

    bbp_get_topic_author_link ( array( 'size' => '60' ) );

    and more so. Is there anything I’m doing wrong?

    Thank you for any help I might get :)

Viewing 8 replies - 1 through 8 (of 8 total)

  • hitkid
    Participant

    @hitkid

    Hey Stephen!

    Thanks so much for the help! :D I should’ve mentioned that I tried those already and they didn’t appear. It works with other bbpress functions, but just not the author avatar as you shared with the codex. I updated the version of bbpress. buddypress and wordpress that I am using to try and see if that worked and still nothing. The avatar shows just fine in the mychildtheme/bbpress/loop-single-topic. It shows up with the topic index shortcode. Any ideas as to what the problem is? I’m pretty confused as to what’s going on!

    Thanks again @netweb !

    Are you only to show the avatar? (i.e. Not their, role or title etc)

    This should work to display only the current topic author user’s avatar without their display name or user role and with an avatar size 60px.
    <?php bbp_topic_author_link( array( 'show_role' => false, 'type' => 'avatar', 'size' => 60 ) ); ?>


    hitkid
    Participant

    @hitkid

    @netweb

    I don’t need their role or title. For some reason the avatars will just not come up in the loop outside of the mychild/bbpress/loop-single-forum.php files and mychild/bbpress/loop-single-topic.php. So it works fine on index pages.

    I’ve tried all of the but nothing

    Here’s what the code looks like right now:

    <?php $args = array( 'post_type' => 'topic', 'posts_per_page' => 10 );
    			$the_query = new WP_Query( $args );?> 
    			
    <?php if ( $the_query->have_posts() ) : ?>
    
      <!-- pagination here -->
    
      <!-- the loop -->
      <?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
       <?php bbp_author_link( array( 'post_id' => bbp_get_forum_last_active_id(), 'size' => 32 ) ); ?>
    	
    	<a class="bbp-topic-permalink" href="<?php bbp_topic_permalink(); ?>" title="<?php bbp_topic_title(); ?>"><?php bbp_topic_title(); ?></a>
      <?php endwhile; ?>
      <!-- end of the loop -->
    
      <!-- pagination here -->
    
      <?php wp_reset_postdata(); ?>
    
    <?php else:  ?>
      <p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>
    <?php endif; ?>

    This worked for getting the original post author, but I need the latest active poster to appear<?php echo get_avatar( get_the_author_meta( 'ID' ), 32 ); ?>

    Is there a wordpress function equivalent for this function: bbp_get_forum_last_active_id() that I can use with get_avatar() ?

    What file do these functions reside in? Maybe I could copy the functions out and make new ones in mychild/functions.php or see if something wrong and replace the file?

    Thank you for the help!


    hitkid
    Participant

    @hitkid

    *edit*
    I’ve tried all of the documentations functions*

    <?php $args = array( ‘post_type’ => ‘topic’, ‘posts_per_page’ => 10 );
    $the_query = new WP_Query( $args );?>
    
    <?php if ( $the_query->have_posts() ) : ?>
    
    <!– pagination here –>
    
    <!– the loop –>
    <?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
    <?php bbp_author_link( array( ‘post_id’ => bbp_get_forum_last_active_id(), ‘size’ => 32 ) ); ?>
    
    <a class=”bbp-topic-permalink” href=”<?php bbp_topic_permalink(); ?>” title=”<?php bbp_topic_title(); ?>”><?php bbp_topic_title(); ?></a>
    <?php endwhile; ?>
    <!– end of the loop –>
    
    <!– pagination here –>
    
    <?php wp_reset_postdata(); ?>
    
    <?php else: ?>
    <p><?php _e( ‘Sorry, no posts matched your criteria.’ ); ?></p>
    <?php endif; ?>

    Robin W
    Moderator

    @robin-w

    For bbPress specific functions, you’ll generally find the functions in template-tags.php files

    bbp_get_forum_last_active_id()

    is in forums

    wp-content/plugins/bbpress/includes/forums/template-tags.php


    hitkid
    Participant

    @hitkid

    thanks @robin-w !

    I’ve tried to use all the avatar functions found in the documentation in the wp_query(), but none are working. I’ve tried it locally with newer updates of buddypress/bbpress and live with a fresh install and nothing.

    This is the actual tag I want to use:
    <?php bbp_author_link( array( 'post_id' => bbp_get_topic_last_active_id(), 'size' => 14 ) ); ?>

    They work perfectly in the mychild/bbpress/loop-single-topic.php , but I just can not get it to work in the query! Is there anything I am missing, or doing wrong?

    Thanks for the help!


    Robin W
    Moderator

    @robin-w

    suspect that there is a variable in loop-sinlge-reply that already exists, but is not there in loop posts, so you’re getting a nil return.

    I’d try hardcoding some to see if you can pinpoint.

    eg look up a bbp post and see who the author is, so if post is 1126 then try

    <?php bbp_author_link( array( ‘post_id’ => 1126, ‘size’ => 14 ) ); ?>

    and see if that produces a result.

    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

Viewing 8 replies - 1 through 8 (of 8 total)

You must be logged in to reply to this topic.