Skip to:
Content
Pages
Categories
Search
Top
Bottom

Custom Topic Sorting

  • @vanndogg

    Participant

    Hi, guys!

    I have a problem with topic filters – i need to filter my topics by custom meta value (date from custom field) in this website http://sopernik.sites.in.ua/ . I have events, what realised like topics, client want to filter these event by date what you can take in custom field.

    Could you help me with it?

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

    Moderator

    untested by this should work

    //change topic order
    add_filter('bbp_before_has_topics_parse_args', 'rew_topic_order_by_meta');
    
    function rew_topic_order_by_meta ($args) {
    	$args['meta_key'] = 'put_meta_key_here' ;
    	$args['orderby']    = 'meta_value' ;
    	$args['order']     = 'DESC' ;  //or ASC if needed
    	return $args ;
    }

    just put your meta_key where it says

    @tapiohuuhaa

    Participant

    I found this also:

    function my_custom_display_topic_index_query () {
    $args[‘orderby’] = ‘date’;
    $args[‘order’] = ‘DESC’;

    return $args;
    }
    add_filter(‘bbp_before_has_topics_parse_args’, ‘my_custom_display_topic_index_query’ );

    You wrote that buttons for that would be complicated, but if I reload the page and use GET-parameters, this way, would this work:

    function my_custom_display_topic_index_query () {
    if($_GET[…]==…) $myOrder=’date’; elseif(…) //or switch – then used a select box)
    if ($_GET[‘descAsc’]==…) $descAsc=’DESC’;
    $args[‘orderby’] = $myOrder;
    $args[‘order’] = $descAsc;

    return $args;
    }
    add_filter(‘bbp_before_has_topics_parse_args’, ‘my_custom_display_topic_index_query’ );

    Buttons or select box would be inside the template and it gets the current webaddress and add desired parameters. If I add also cookies, the change would not need to do every time.

    @tapiohuuhaa

    Participant

    Exactly I think this code:

    function my_custom_display_topic_index_query () {
    global $_GET;
    if($_GET[‘myOrderBy’])$myOrderBy=$_GET[‘myOrderBy’];else $myOrderBy=’last_edited’;
    if($_GET[‘myOrder’])$myOrder=$_GET[‘myOrder’];else $myOrder=’DESC’;
    $args[‘orderby’] = $myOrderBy;
    $args[‘order’] = $myOrder;

    return $args;
    }
    add_filter(‘bbp_before_has_topics_parse_args’, ‘my_custom_display_topic_index_query’ );

    function printSelections(){
    global $_SERVER;
    return ‘<div class=”queries”><form action=”https://&#8217; . $_SERVER[‘HTTP_HOST’] . $_SERVER[‘REQUEST_URI’].'”><table class=”querytable”><tr><td><select name=”myOrderBy”><option value=”post_modified”>Viimeisin muutos</option><option value=”post_date”>Luontipäivä</option><option value=”post_title”>Nimi/option><option value=”post_author”>Tekijä/option></select></td><td><input name=”myOrder” type=”radio” value=”DESC” />Laskeva</td><td><input name=”myOrder” type=”radio” value=”ASC” />Nouseva</td></tr></table></form>’;
    }

    add_shortcode( ‘printSelections’, ‘printSelections’ );
    // Add do_shortcode(‘printSelections’); to loop-forums.php
    <li class=”bbp-header”>

    <ul class=”forum-titles”>
    <li class=”bbp-forum-info”><?php _e( ‘Forum’, ‘bbpress’ ); ?><?php topPostLinksEcho(); ?>
    <li class=”bbp-forum-topic-count”><?php _e( ‘Topics’, ‘bbpress’ ); ?>
    <li class=”bbp-forum-reply-count”><?php bbp_show_lead_topic() ? _e( ‘Replies’, ‘bbpress’ ) : _e( ‘Posts’, ‘bbpress’ ); ?>
    <li class=”bbp-forum-freshness”><?php _e( ‘Freshness’, ‘bbpress’ ); ?>

    <?php do_shortcode(‘[printSelections]’); ?>

    @robin-w

    Moderator

    depends on how you define complicated – solutions are frequently only a few lines of code, but getting there takes the time 🙂

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