Ajax Search Pro Knowledge Base
Buy Ajax Search Pro!DocumentationGet SupportDevelopment
  • Knowledge Base
  • Safe Coding Guideline
  • Hooks
    • Filters
      • Query & Output
        • asp_query_args
        • asp_query_{type}
        • asp_cached_content
        • asp_pre_get_front_filters
        • asp_before_ajax_output
        • asp_shortcode_output
        • asp_print_search_query
      • Keyword Suggestions
      • Search Results
        • asp_suggested_phrases
        • asp_results
        • asp_cpt_results
        • asp_buddyp_results
        • asp_attachment_results
        • asp_comment_results
        • asp_blog_results
        • asp_terms_results
        • asp_peepso_group_results
        • asp_peepso_activities_results
        • asp_only_keyword_results
        • asp_only_non_keyword_results
        • asp_result_groups
      • CSS & JS
        • asp_load_js
        • asp_load_css
        • asp_load_css_js
      • Template & Output
        • asp_icl_t
      • Index Table Related
        • asp_index_on_save_stop
        • asp_indexing_keywords
        • asp_indexing_string_pre_process
        • asp_indexing_string_post_process
        • asp_post_content_before_tokenize_clear
        • asp_post_content_before_tokenize
        • asp_post_excerpt_before_tokenize
        • asp_post_title_before_tokenize
        • asp_file_contents_before_tokenize
        • asp_post_permalink_before_tokenize
        • asp_index_terms
        • asp_post_custom_field_before_tokenize
        • asp_index_cf_contents_before_tokenize
        • asp_index_before_shortcode_execution
        • asp_index_after_shortcode_execution
    • Templating
      • Filter layouts Templating
      • Result Templating
    • Constants
  • Frontend Filters
    • Taxonomy Filters
      • Restricting results to the same category as the current post object
      • How to automatically check/select filter values based on the archive page?
    • Frontend filters API
  • Tips & Miscellaneous
    • Divi
      • Divi Blogs Live Search and Filter
    • Jet Engine
      • Jet Engine Listing Grid Live Search and Filter
      • Searching Jet Engine Custom Meta Storage fields
    • Tutorials
      • PDF results thumbnails
      • Demo setup: Staff search and Filter
      • Demo Setup: WooCommerce Search
      • Demo setup: WooCommerce Shop Search and Filter
      • Demo Setup: Events Search – Events Manager
      • Demo Setup: Events Search – The Events Calendar
      • Compact ‘pop-out’ search bar placement on specific pages only
      • Index Table – Indexing ACF repeater field titles and contents
      • Change Suggested Phrases conditionally
      • How to add shortcode to the results content?
      • How to add variables to the “redirect to url” or the “show more url”?
      • Indexing Shortcodes within custom field contents
    • Post Types
      • Index Table - Indexing child post contents to parent
      • Limit results to specific post IDs only
      • Filter posts (or CPT) which user can’t access
      • Restricting results by user Groups using the Groups plugin by itthinx
      • Limiting results to specific posts by parent ID
      • Limit results to current page children
      • Excluding posts or CPT by parent ID(s)
      • Searching posts, pages (or any CPT) by specified keywords only, nothing else
      • Showing the post type name in result title or content
      • Searching within given categories/taxonomy terms only
      • Search only in the same category as the current post or page (single page)
      • Search only within the current category (or any taxonomy) archive
      • Filtering pages by page template
    • Taxonomy Terms
      • Displaying taxonomy name in taxonomy term results
      • Limiting taxonomy term results to specific term IDs only
    • WooCommerce
      • Displaying On Sale products only in WooCommerce
      • Ordering product by stock status
      • Making a product in-stock & out of stock filter
      • Add to cart button for Vertical and Horizontal results
      • Get formatted price in result title or in content
      • Showing products in-stock only
      • Showing in-stock and backorder products only
      • Excluding hidden catalog products
      • Showing featured products first
      • How to search products & product SKU?
      • How to search Products by variation SKUs?
      • Search product attributes
      • How to search users by city, state, zip code… ?
    • Compatibility
      • WPML Compatibility issues and fixes
    • Files & Media
      • Searching Image EXIF metadata
    • Other
      • Restrict results from the current author archive page
      • Presetting search options via a custom URL
      • Matomo analytics tracking integration
      • Replace search keywords (whole words)
      • Replace or remove characters from search phrase
      • Adding spaces in search phrase between alphabetics and numbers
      • How to change the results URL to something else?
      • Numbering the results
      • How to use the search without the live ajax feature, as a regular search?
      • Empty search input field on the search results page
      • Singular and Plural keywords index
  • Other
    • SearchQuery
    • REST API
    • Building a custom REST API
    • Javascript API
    • Javascript Hooks
      • asp_redirect_url
      • asp_search_data
      • asp_live_load_html
      • asp_search_html
      • asp_compact_width
    • Theme Functions
Powered by GitBook
On this page
  • Filter layouts Templating
  • Important! Before you start
  • Directory Structure
  • Template file variables
  • Example usage
  1. Hooks
  2. Templating

Filter layouts Templating

Filter layouts Templating

This guide is for advanced users/developers. Please do not modify the template files if you have no experience in HTML/PHP programming.

From plugin version 4.16 the search plugin generates HTML output based on specific template files. This means, that you are now able to modify HTML structure of every front-end filter.

You can find these files in the wp-content/plugins/ajax-search-pro/includes/views/filters/ directory.

Important! Before you start

Do not make changes directly to these files! To have permanent changes make a new folder called “asp” in your theme directory like so:

wp-content/themes/your-theme-name/asp/

..and a sub-directory as well:

wp-content/themes/your-theme-name/asp/filters/

and copy the desired files (including the subdirectories) from

wp-content/plugins/ajax-search-pro/includes/views/filters/

directory there. The plugin will automatically look and use the files from the theme “asp” directory if they exist. Now you can edit these copied files and prevent future search plugin updates to remove your changes. Make sure to always maintain the sub-directory structure, otherwise the files may not be found.

Directory Structure

The files are structured by filter type and display mode:

ajax-search-pro/includes/views/filters/{type}/asp-{type}–{display_mode}.php

The list below is relative to the wp-content/plugins/ajax-search-pro/includes/views/filters/ directory.

Search and reset buttons

  • /button/asp-button-filter.php

  • /button/asp-button-footer.php

  • /button/asp-button-header.php

Content type filters

  • /content_type/asp-content_type-checkboxes.php

  • /content_type/asp-content_type-dropdown.php

  • /content_type/asp-content_type-footer.php

  • /content_type/asp-content_type-header.php

  • /content_type/asp-content_type-radio.php

Custom Field filters

  • /custom_field/asp-cf-checkboxes.php

  • /custom_field/asp-cf-datepicker.php

  • /custom_field/asp-cf-dropdown.php

  • /custom_field/asp-cf-dropdownsearch.php

  • /custom_field/asp-cf-footer.php

  • /custom_field/asp-cf-header.php

  • /custom_field/asp-cf-hidden.php

  • /custom_field/asp-cf-multisearch.php

  • /custom_field/asp-cf-radio.php

  • /custom_field/asp-cf-range.php

  • /custom_field/asp-cf-slider.php

  • /custom_field/asp-cf-text.php

Date filters (custom post type date filter, not custom field date filter)

  • /date/asp-date-filter.php

  • /date/asp-date-footer.php

  • /date/asp-date-header.php

Generic filters

  • /generic/asp-generic-checkboxes.php

  • /generic/asp-generic-dropdown.php

  • /generic/asp-generic-footer.php

  • /generic/asp-generic-header.php

  • /generic/asp-generic-radio.php

Post type filters

  • /post_type/asp-post-type-checkboxes.php

  • /post_type/asp-post-type-dropdown.php

  • /post_type/asp-post-type-footer.php

  • /post_type/asp-post-type-header.php

  • /post_type/asp-post-type-radio.php

Taxonomy term filters

  • /taxonomy/asp-tax-checkboxes.php

  • /taxonomy/asp-tax-dropdown.php

  • /taxonomy/asp-tax-dropdownsearch.php

  • /taxonomy/asp-tax-footer.php

  • /taxonomy/asp-tax-header.php

  • /taxonomy/asp-tax-multisearch.php

  • /taxonomy/asp-tax-radio.php

Template file variables

For all template files there is one universally used variable, the $filter object. Since all of the filter types are a bit different, we recommend always starting with the original template to see which attributes are used. Most common uses:

  • $filter->data (array) – contains all the static information about the filter, such as the box header texts, placeholder, date storage methods etc..

  • $filter->get() -> returns each individual filter value object. Should be used within a foreach statement.

Some templates might use different helper variables as well, such as the taxonomy filters the $taxonomy variable or the custom field filters the $field_name variable.

Example usage

Let’s assume, you need to add an additional attribute and a class name to each radio value within the custom field radio filter.

1. Make a copy of the original file

Copy: wp-content/plugins/ajax-search-pro/includes/views/filters/custom_field/asp-cf-radio.php

to: wp-content/themes/your-child-theme/asp/filters/custom_field/asp-cf-radio.php

2. Make the changes in the copy

Original:

<?php foreach($filter->get() as $radio): ?>
    <label class="asp_label">
        <input type="radio" class="asp_radio" name="aspf[<?php echo $field_name; ?>]"
                <?php echo $radio->default ? 'data-origvalue="1"' : ''; ?>
               value="<?php echo esc_attr($radio->value); ?>"
            <?php echo $radio->selected ? "checked='checked'" : ""; ?>/>
        <?php echo esc_html($radio->label); ?>
    </label><br>
<?php endforeach; ?>

Changed:

<?php foreach($filter->get() as $radio): ?>
    <label class="asp_label my_custom_class" data-myattr="my custom attr">
        <input type="radio" class="asp_radio" name="aspf[<?php echo $field_name; ?>]"
                <?php echo $radio->default ? 'data-origvalue="1"' : ''; ?>
               value="<?php echo esc_attr($radio->value); ?>"
            <?php echo $radio->selected ? "checked='checked'" : ""; ?>/>
        <?php echo esc_html($radio->label); ?>
    </label><br>
<?php endforeach; ?>

PreviousTemplatingNextResult Templating

Last updated 4 years ago