Skip to:
Content
Pages
Categories
Search
Top
Bottom

filter topic on date base

  • @divyesh25

    Participant

    Hi everyone,

    Any one know how to filter topics on date base. means i want to list all last 5 days topics.

    i see code this code in function bbp_has_topics( $args = '' )

    
    $default = array(
    		'post_type'      => bbp_get_topic_post_type(), // Narrow query down to bbPress topics
    		'post_parent'    => $default_post_parent,      // Forum ID
    		'meta_key'       => '_bbp_last_active_time',   // Make sure topic has some last activity time
    		'orderby'        => 'meta_value',              // 'meta_value', 'author', 'date', 'title', 'modified', 'parent', rand',
    		'order'          => 'DESC',                    // 'ASC', 'DESC'
    		'posts_per_page' => bbp_get_topics_per_page(), // Topics per page
    		'paged'          => bbp_get_paged(),           // Page Number
    		's'              => $default_topic_search,     // Topic Search
    		'show_stickies'  => $default_show_stickies,    // Ignore sticky topics?
    		'max_num_pages'  => false,                     // Maximum number of pages to show
    	);
    

    is it possible to pass date filter in function bbp_has_topics argument.

Viewing 4 replies - 1 through 4 (of 4 total)
  • @robin-w

    Moderator

    yes it should be as bbpress just uses wp_query once args has been parsed.

    see

    https://codex.wordpress.org/Class_Reference/WP_Query dates are quite a way down

    untested but something like

    $week = date( 'W' );
    $year = date( 'Y' );
    bbp_has_topics( array( 'year' => $year, '&w' => $week ) );
    

    would do last 5 days

    @divyesh25

    Participant

    hi Robin,

    thanks for reply.. i am implemented your suggestion, but not getting result. can You explain me in detail with code?

    thanks

    @robin-w

    Moderator

    You explain me in detail with code?

    Can you explain what you are trying to do and where on your site eg put a shortcode on the front page, add a widget that does this etc.

    @divyesh25

    Participant

    Hi robin,

    i want list that all topics since user last visit to site, so for that some how i am update user last activity date and time and when user logged in next time i am get that date and time. so using this date & time i want to list topics since last visit of user.

    i hope u got it what i want to say. the code is below. if i do any mistake please suggest me.

    if u have better solution then please suggest me.

    thanks

    <?php$week = date( ‘W’ );
    $year = date( ‘Y’ );?>
    <?php if ( bbp_has_topics(‘author’ => 0, ‘order’ => ‘DESC’, ‘post_parent’ => ‘any’,’year’ => $year, ‘&w’ => $week) ) : ?>
    <?php while ( bbp_topics() ) : bbp_the_topic(); ?>
    <?php bbp_get_template_part( ‘loop’, ‘single-topic’ ); ?>
    <?php endwhile; ?>
    <?php else : ?>
    <?php bbp_get_template_part( ‘feedback’, ‘no-topics’ ); ?>
    <?php endif; ?>

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