This website uses cookies to personalize your experience. By using this website you agree to our cookie policy.

Reply To: Searching private and hidden groups

Home Forums Product Support Forums Ajax Search Pro for WordPress Support Searching private and hidden groups Reply To: Searching private and hidden groups

#20967
Ernest MarcinkoErnest Marcinko
Keymaster

Hi,

Thank you, I may have found a possible solution, I am not sure. If you add the parent forum of that document to the filters list, it should be excluded now.

For future reference, I have constructed the following code into the functions.php file in your child theme directory:

// -- AJAX SEARCH PRO SPECIFIC --
add_filter('asp_results', 'asp_results_filter_attachments', 10, 4);
function asp_results_filter_attachments($results, $id, $is_ajax, $args) {
  if ( isset($args['post_meta_filter']) ) {
    $ids = array();
    foreach ( $args['post_meta_filter'] as $pm ) {
      if ( $pm['key'] == '_bbp_forum_id' )
        $ids[] = $pm['value'];  
    }
    if (count($ids) > 0) {
      foreach ($results as $k => &$r) {
        if (isset($r->post_type) && $r->post_type == 'attachment') {
          $pid = wp_get_post_parent_id( $r->id );
          $forum_id = (int)get_post_meta($pid, '_bbp_forum_id', true);
          while ( !empty($forum_id) ) {
            if ( in_array($forum_id, $ids) ) {
              unset($results[$k]); 
              break; 
            }
            $forum_id = wp_get_post_parent_id( $forum_id );
          }
        }
      }
    }
  }
 
  return $results;
}