Skip to:
Content
Pages
Categories
Search
Top
Bottom

meta_filter and sort


  • moui
    Participant

    @moui

    Hi,

    I am having trouble with a meta_filter in my groups-loop. Here is a gist with the filter function and its hook registration.

    https://gist.github.com/moui72/cc1a32a39630a67596610cdadb84893a

    It works as expected, except I would like the results to be sortable via the default order options as well as custom ones, but currently the sorting action resets my meta query.

    The sorting I mean is via this thingy:

    <label for="groups-order-by"><?php _e( 'Order By:', 'buddypress' ); ?></label>
    <select id="groups-order-by">
      <option value="active"><?php _e( 'Last Active', 'buddypress' ); ?></option>
      <option value="popular"><?php _e( 'Most Members', 'buddypress' ); ?></option>
      <option value="newest"><?php _e( 'Newly Created', 'buddypress' ); ?></option>
      <option value="alphabetical"><?php _e( 'Alphabetical', 'buddypress' ); ?></option>
    
      <?php do_action( 'bp_groups_directory_order_options' ); ?>
    
    </select>

    The event handler for the above select is being added to the select object by some js, and I am not sure if that is due to buddypress or the parent theme (CBOX-theme) that I am using, but in any case it is sending an AJAX request to buddypress. As stated, these requests clear my meta_query.

    I am currently using a simple GET form action to apply my filters, so I am guessing what I need to do is to loop my filters in as an AJAX request instead. Will that fix my issue?

Viewing 1 replies (of 1 total)

  • moui
    Participant

    @moui

    I should add that I am using some forms as a UI for the end user to control these filters. So what I really want to know is, what is the best practice for providing the user’s input to the bp ajax handler and passing it through to my filter?

    I also want to have that data available when I am emitting the form so I can persist the selected options.

    I am currently displaying the form via a function in a BP_Group_Extension class. Here’s the function that provides it:

      public function display_group_filters($raw_filters = []) {
        $sl = [];
        $tf_semester = [];
        $tf_year = [];
        if(!empty($raw_filters['student_level'])){
          $sl = $raw_filters['student_level'];
        }
    
        if(!empty($raw_filters['semester'])){
          $tf_semester = $raw_filters['semester'];
        }
        if(!empty($raw_filters['year'])){
          $tf_year = $raw_filters['year'];
        }
    
        $out = '
        <div id="group-dir-filter"
          class="col-xs-12 col-md-3 col-md-pull-9" role="filter">
          <form action="" method="get" id="filters">
            <h3>Filters</h3>
            <p>
            Use the controls below to limit what projects are shown.
            </p>
            <div class="filter-section col-xs-6 col-md-12">
              <h4>Student level</h4>';
        $out .= $this->student_levels_markup($sl, false);
        $out .= '
            </div>
            <div class="filter-section col-xs-6 col-md-12">
              <h4>Timeframe</h4>';
        $out .= $this->semester_markup($tf_semester, $tf_year, false);
        $out .= '
            </div>
            <input type="hidden" name="action" value="tp_filter_group" />
            <button class="btn btn-warning" type="button"
            onclick="window.location.href=\''.esc_url( home_url( '/' ) ).'/groups\'" />Reset</button>
            <button type="submit" class="btn btn-info">Filter</button>
          </form>
        </div>';
        echo $out;
        return $out;
      }
Viewing 1 replies (of 1 total)
  • You must be logged in to reply to this topic.
Skip to toolbar