Skip to:
Content
Pages
Categories
Search
Top
Bottom

bbPress latest topics by activity


  • Sami Keijonen
    Participant

    @samikeijonen

    I finally started playing with bbPress. There are lot to learn because I want to display topics totally differently what is the default output.

    First I want to display latest topics by latest activity like usual. I’ve created archive-topic.php in my theme so I can decide output.

    After that I can filter topic post type so that topics are ordered by latest activity.

    add_action( 'pre_get_posts', 'my_filter_topic' );

    function my_filter_topic( $query ) {

    if( $query->is_main_query() && is_post_type_archive( 'topic' ) ) {

    $query->set( 'meta_key', '_bbp_last_active_id' );
    $query->set( 'orderby', 'meta_value_num' );
    $query->set( 'order', 'DESC' );

    }

    }

    But this doesn’t display sticky posts first. They are more like last. Does someone have an idea how I get sticky posts to show first?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Stickies are pretty difficult to include with custom post types as WordPress doesn’t have native support for them. I’d suggest you look at how the bbp_has_topics() function works: https://bbpress.svn.wordpress.org/trunk/includes/topics/template-tags.php

    If you look through that function you’ll see that bbPress manually pulls in all of the sticky posts and then passes the array of IDs to the “include” parameter in a second query.


    Sami Keijonen
    Participant

    @samikeijonen

    Thanks Pippin. Justin Tadlock gave me same advice to go into that file. Let me tell you that it’s little out of my head. But I definitely try this out and report here if I find a solution.

    $query->set( 'meta_key', '_bbp_last_active_time' );
    $query->set( 'orderby', 'meta_value' );

    This actually works better because now sticky posts are in their ‘natural’ position, not last.


    Sami Keijonen
    Participant

    @samikeijonen

    Hmmm and now I’m thinking why there is no sticky post support for custom post types in WP.

    There’s a trac ticket on the topic somewhere.

Viewing 4 replies - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.
Skip to toolbar