Ajax Search Pro Documentation
Get Ajax Search Pro!Get SupportKnowledge BaseDevelopment
  • Ajax Search Pro Documentation
  • GDPR and Cookie policy
  • Video Guides
  • Plugin Updates
    • Automatic Updates
      • Activation on Development and Staging environments
      • Managing purchase codes
      • Purchase Code (license key)
    • Manual Updates
    • Safe Update Guide
    • Plugin update issues or errors
    • Disabling update check
  • Installation instructions
    • Uninstallation & Reset
  • Getting started
    • Importing from the Lite version
    • Editor Blocks
    • Search Shortcodes
    • Search Widget
    • Gutenberg and Other Page Editors
    • Replacing the default theme search bar
    • Placing the search shortcode in theme files
    • Search as menu item
    • Custom result box position
    • Custom filters box position
    • Shortcode generator
  • Search Sources
    • Search Engine
    • Post, Page, Product and other Post Type Search
    • Searching Titles, Content, Excerpt
    • Search in custom fields
      • Search By Product SKU
    • Search by categories, tags or other terms
    • Search in Attachments
      • Mime types table
    • Search in File contents (pdf, word, excel etc..)
    • Search in Users
      • User meta fields
    • Limits (number of results)
    • Categories and terms as results
    • Image options
    • Result ordering
    • Peepso Groups & Group activities search
    • Grouping title duplicates
  • Behavior
    • Return/Enter key and Magnifier icon click actions
    • Search logic (primary and secondary)
      • Exact Matches vs Fuzzy Matches
      • Search logics explained
    • Live search triggering events
    • Results page override
    • Results, Archive Page and Shop Live Search and Filter
  • Elementor Integration
    • Elementor Pro Posts Widget Live Filter
    • Elementor Loop Grid Integration
    • Elementor Pro Product Widget Live Filter
    • Custom results page with Elementor Pro
    • Elementor custom search page archive override and live filter
  • Other Integration
    • Jet Engine Listing Grid Integration
  • Multisite Settings
  • Frontend Search Settings & Search Filters
    • Settings layout, position and visibility
    • Generic Selectors
    • Content Type filters
    • Date filters
    • Category and Taxponomy term filters
    • Post type Filters
    • Custom field filters - selectors
    • Search button
    • Reset button
  • Layout Settings
    • Result Layout Types
    • Results information box
    • Results position & snap
    • Content, author, date and description in results
    • More results loader and infinite scroll feature
    • Results behavior
    • Results text keyword highlighter
    • Compact search box layout
    • Auto Populate - Automatic search results on initial page load
  • Autocomplete and Keyword suggestions
    • Autocomplete
    • Results and Keyword suggestions
    • "Try these" - suggested phrases
  • Theme Options - Visual changes to the search bar
    • Theme chooser
    • Preview
    • Search box and input field layout
    • Settings and Magnifier icon
    • Settings dropdown
    • Typography
  • Index Table
    • Generating the index table
    • Enabling index table engine
    • File Content Search Addon
    • Index table FAQ
    • Synonyms
  • Relevance Options
  • Advanced Options and Uses
    • Using the Results shortcode as a custom results page
    • Shortcodes in results content
    • HTML tags in results
    • Primary and Secondary title and description fields
    • Advanced title and Content fields
      • User Search - Advanced Title and Content fields
    • Excluding & Including results
      • Exclude by category or terms
      • Exclude or Include by authors (users)
      • Exclude or Include by date
      • Exclude by Item or ID
      • Include by ID
      • Include by categories or terms (restrict to category)
      • Exclude or Include by custom field values
    • Grouping results
    • Keyword Exception & Exclusions
  • Result priority settings
    • Individual Priorities
    • Priorities by Rules (priority groups)
  • Performance Tuning
    • Fine tuning the search configuration
    • Cache
    • Visual performance
    • Ajax performance tracker
  • Compatibility Settings
    • Javascript Compatibility
  • Google Analytics Integration (GA4)
    • Tracking with Google Site Tag (gtag.js)
    • Tracking with Google Tag Manager
    • Site Search Tracking
  • Troubleshooting
    • Styling issues
    • The response data is missing from the ajax request error message
  • Translating components
    • Translating with WPML
    • Translating with Polylang
  • Pre-Purchase FAQ
  • Plugin API
    • Actions list and usage
    • Filters list and usage
    • asp_query_args filter
    • Theme functions
    • Front-end filters API
    • Javascript API
  • Other Useful Things
    • Additional search keywords for post types
    • Negative keywords
    • Meta box on post editor screen
Powered by GitBook
On this page
  • Usage examples
  • Filters list
  1. Plugin API

Filters list and usage

PreviousActions list and usageNextasp_query_args filter

Last updated 7 years ago

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 , and second is a simple .

For more examples, check the .

/** 
 * 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);
category titles to the result titles
result numbering
knowledge base