> For the complete documentation index, see [llms.txt](https://documentation.ajaxsearchpro.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://documentation.ajaxsearchpro.com/plugin-api/filters-list-and-usage.md).

# Filters list and usage

Filters are used to modify data on specific events. You can create functions based on the filters list below with the available parameters. Filters are a great way of modifying results without touching the code.

## Usage examples

Here you can see two basic examples of filter usage. One is adding [category titles to the result titles](https://wp-dreams.com/knowledge-base/showing-the-category-titles-in-the-result-title/), and second is a simple [result numbering](https://wp-dreams.com/knowledge-base/numbering-the-results/).

For more examples, check the [knowledge base](https://wp-dreams.com/knowledgebase/).

```
/** 
 * Add category titles to result titles
 * 
 * @link: https://wp-dreams.com/knowledge-base/showing-the-category-titles-in-the-result-title/
 */
add_filter( 'asp_pagepost_results', 'asp_add_category_titles', 1, 1 );

function asp_add_category_titles( $pageposts ) {
  foreach ($pageposts as $k=>$v) {

    // Get the post categories
    $post_categories = wp_get_post_categories( $pageposts[$k]->id );
    $cats = "";

    // Concatenate category names to the $cats variable
    foreach($post_categories as $c){
        $cat = get_category( $c );
        $cats = " ".$cat->name;
    }                 

    // Modify the post title
    $pageposts[$k]->title  .= " ".$cats;
  }

  return $pageposts;
}


/** 
 * Numbering the results
 * 
 * @link: https://wp-dreams.com/knowledge-base/numbering-the-results/
 */
add_filter( 'asp_results', 'asp_number_results', 1, 1 );

function asp_number_results( $results ) {
  var $num = 1;
  foreach ($results as $k=>$v) {
    // Modify the post title
    $results[$k]->title  = $num . ". " . $results[$k]->title;
    $num++;
  }

  return $results;
}
```

## Filters list

```
/** 
 * Filters, if caching is not activated 
 *
 * Parameters explained:
 *      $r -> the result object (id, title, content, link, author, date)
 *      $results -> associative array of result objects
 *      $s -> search phrase
 */

$allpageposts = apply_filters( 'asp_pagepost_results', $allpageposts );
$allcommentsresults = apply_filters( 'asp_comment_results', $allcommentsresults );
$buddypresults = apply_filters( 'asp_buddyp_results', $buddypresults );
$blogresults = apply_filters( 'asp_blog_results', $blogresults ); 
$results = apply_filters( 'asp_only_keyword_results', $results );
$results = apply_filters( 'asp_only_non_keyword_results', $results );
$results = apply_filters( 'asp_results', $results );
$s = apply_filters( 'asp_search_phrase_before_cleaning', $s );
$s = apply_filters( 'asp_search_phrase_after_cleaning', $s );

$r = apply_filters('asp_result_before_prostproc', $r); 
$r->title = apply_filters( 'asp_result_title_before_prostproc' , $r->title, $r->id);
$r->content = apply_filters( 'asp_result_content_before_prostproc' , $r->content, $r->id);
$r->image = apply_filters( 'asp_result_image_before_prostproc' , $r->image, $r->id);
$r->author = apply_filters( 'asp_result_author_before_prostproc' , $r->author, $r->id);
$r->date = apply_filters( 'asp_result_date_before_prostproc' , $r->date, $r->id);

$r = apply_filters('asp_result_after_prostproc', $r); 
$r->title = apply_filters( 'asp_result_title_after_prostproc' , $r->title, $r->id);
$r->content = apply_filters( 'asp_result_content_after_prostproc' , $r->content, $r->id);
$r->image = apply_filters( 'asp_result_image_after_prostproc' , $r->image, $r->id);
$r->author = apply_filters( 'asp_result_author_after_prostproc' , $r->author, $r->id);
$r->date = apply_filters( 'asp_result_date_after_prostproc' , $r->date, $r->id);

/* With cache activated */
// The HTML output of cached content 
$cache_content = apply_filters( 'asp_cached_content', $cache_content);
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://documentation.ajaxsearchpro.com/plugin-api/filters-list-and-usage.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
