Filters /

Filter Hooks

Hooks provide developers with access points to modify core plugin functionality by altering or extending returned data.

The following filters and hooks are available when using the Filters add-on:


alm_filters_{id}_{key}

This filter provides a method of customizing the returned filter selections of a specific filter by key.

  • id: The unique filter ID
  • key: The target query parameter
    When filtering by custom field or taxonomy, the key parameter must be the meta_key or taxonomy slug value.
// id: blog, key: category
add_filter( 'alm_filters_blog_category', function() {    
   $values = []; // Define empty array.      
   $args = array(
	   'order' => 'ASC',
	   'orderby' => 'name',
   );  
   $terms = get_categories($args); // Get all categories.
   
   // Loop terms.
   if($terms){      	  
      foreach( $terms as $term ) { 
         $values[] = array(
            'label' => $term->name,
            'value' => $term->slug
         );
      }		
      // Add 'Show All' option.
      $values[] = array( 
         'label' => 'Show All',
         'value' => ''
      );		
   }		
   return $values; // Return values	
});
PHP

The code snippet above returns custom filter values ordered by name in ascending order for the category query of the blog filter.

Note: When using this filter you must return both a label and value in the array.

alm_filters_{id}_{key}_before

This filter will prepend custom filter options to the start of a dynamically populated term list of filters.

  • id: The unique filter ID
  • key: The target query parameter
    When filtering by custom field or taxonomy, the key parameter must be the meta_key or taxonomy slug value.
// id: blog, key: category
add_filter( 'alm_filters_blog_category_before', function() {
   $values = array(
      array(
         'name' => __( 'Show All', 'framework' ),
         'slug' => '' // Leave empty to reset the query.
      )
   );

   return $values;
});
PHP

The code snippet above will add a ‘Show All’ option to the start of the category filter.

Note: The filter can only be used with Taxonomy, Category, and Tag filters when using Radio and Checkbox field types.

alm_filters_{id}_{key}_after

This filter will append custom filter options to the end of the dynamically populated term list of filters.

  • id: The unique filter ID
  • key: The target query parameter
    When filtering by custom field or taxonomy, the key parameter must be the meta_key or taxonomy slug value.
// id: blog, key: category
add_filter( 'alm_filters_blog_category_after', function() {
   $values = array(
      array(
         'name' => __( 'Show All', 'framework' ),
         'slug' => '' // Leave empty to reset the query.
      )
   );
   return $values;
});
PHP

The code snippet above will add a ‘Show All’ option to the end of the category filter.

Note: The filter can only be used with Taxonomy, Category, and Tag filters when using Radio and Checkbox field types.

alm_filters_{id}_{key}_title

This filter will set the title text of a specific filter block.

  • id: The unique filter ID
  • key: The target query parameter
    When filtering by custom field or taxonomy, the key parameter must be the meta_key or taxonomy slug value.
// id: listing, key: category
add_filter( 'alm_filters_listing_category_title', function() { 
   return __('Categories', 'framework');
});
PHP

The code snippet above will set Categories as the title text for the category filter group.

Note: This filter is useful on multilingual sites built with WPML or Polylang where titles are required to be localized across languages. 

alm_filters_{id}_{key}_label

This filter will set the label of a filter block.

  • id: The unique filter ID
  • key: The target query parameter
    When filtering by custom field or taxonomy, the key parameter must be the meta_key or taxonomy slug value.
// id: listing, key: tag
add_filter( 'alm_filters_listing_tag_label', function() { 
   return '--'. __('Select a Tag', 'your-text-domain') .'--';
});
PHP

The code snippet above will set Select a Tag as the label for the tag filter group.

Note: This filter is useful on multilingual sites built with WPML or Polylang where labels are required to be localized across languages. 

alm_filters_{id}_{key}_default

This filter will set a default fallback value for a filter block.

  • id: The unique filter ID
  • key: The target query parameter
    When filtering by custom field or taxonomy, the key parameter must be the meta_key or taxonomy slug value.
// [[ajax_load_more post_type="work,post"]]
// id: search, key: post_type
add_filter( 'alm_filters_search_post_type_default', function() { 
   return 'work,post';
});
PHP

The code snippet above will set work and post as fallback post_type value when zero items are selected.

Note: Return values in this hook should (in most cases) directly relate to values already set in the core Ajax Load More shortcode.

alm_filters_{id}_{key}_selected

This filter will set a default pre-selected value for a filter block and is available for the radio, checkbox, and select field types only.

  • id: The unique filter ID.
  • key: The target query parameter (key).
    When filtering by custom field or taxonomy, the key parameter must be the meta_key or taxonomy slug value.
// [[ajax_load_more post_type="work" category="design"]]
// id: portfolio, key: category
add_filter( 'alm_filters_portfolio_category_selected', function() { 
   return 'design';
});
PHP

The code snippet above will set design as the pre-selected category value of the portfolio filter group.

Note: When using this filter you must also set this value in your core Ajax Load More shortcode.

alm_filters_{id}_{key}_default_select_option

Filters the returned value of a select elements default option.

// [[ajax_load_more post_type="work" category="design"]]
// id: portfolio, key: category
add_filter( 'alm_filters_portfolio_category_default_select_option', function() { 
   return __( '--Make a Selection--', 'framework' );
});
PHP

alm_filters_select_class

Adds custom classes to select element wrappers. This is useful for users who are using select replacement techniques.

add_filter( 'alm_filters_select_class', function() {
   return 'my_select select2';
});
PHP

alm_filters_button_text

Set a default value of submit button label.

add_filter( 'alm_filters_button_text', function() {
   return __('Submit Filter', 'your-text-domain');
});
PHP

alm_filters_title_element

Update the default HTML of each filter title element.

add_filter( 'alm_filters_title_element', function() {
   return 'h2'; // default = h3
});
PHP

alm_filters_edit

Disable the filter edit button for logged-in (admin) users.

add_filter( 'alm_filters_edit', '__return_false' );
PHP

alm_filters_range_slider_reset_label

Change the default label of the reset/clear button used with the Range Slider field type.

// Default: Reset
add_filter( 'alm_filters_range_slider_reset_label', function() {
   return __('Clear', 'framework');
});
PHP

alm_filters_reset_button_label

This filter will change the label of the Reset filters button.

add_filter( 'alm_filters_reset_button_label', function() {
   return __( 'Clear Filters', 'framework' );
} );
PHP

alm_filters_public_taxonomies

This filter will enable all taxonomies (even non-public) to be a option when creating a Taxonomy filter in the Ajax Load More admin. By default, only public taxonomies are displayed.

add_filter( 'alm_filters_public_taxonomies', '__return_false' );
PHP

alm/filters/{id}/{meta_key}/values_order

Allows for ordering of the returned meta query values when using a custom field query. By default, custom fields are returned in asc order.

Available ordering options are asc, desc, numeric, numeric_desc

// id: movies 
// meta_key: genre
add_filter( 'alm/filters/movies/genre/values_order', function() {
	return 'desc';
} );
PHP

alm/filters/single_expand_toggle

Allow only one filter group to be expanded at a time. When enabled, expanding a new filter group will automatically collapse any previously expanded group, providing a cleaner and more organized user interface for your filters.

// Enable single expand toggle for all filters. 
add_filter( 'alm/filters/single_expand_toggle',  '__return_true' );

// Enable single expand toggle for the 'movies' filter only.
add_filter( 'alm/filters/movie/single_expand_toggle',  '__return_true' );
PHP

Term Query Hooks

Taxonomy term and author filters are returned using a set of default query arguments to order terms alphabetically and remove empty options from the listing.

Use the following filter hooks to modify the arguments ( child_of, order, orderby, hide_empty etc.) of an author, category, tag, or taxonomy term query.

Author: alm_filters_{id}_author_args

This filter will adjust the arguments of an author query.

  • id: The unique filter ID
// [[ajax_load_more_filters id="archive"]]
function my_filters_author_args($args){
   // Adjust query $args.
   $args['order'] = 'ASC';
   $args['orderby'] = 'login';
   return $args;	
}
add_filter( 'alm_filters_archive_author_args', 'my_filters_author_args');
PHP

The code snippet above will order an author filter listing by login in ascending order.

Note: The author query uses the WordPress core get_users function – all accepted arguments can be used in this filter.

Category: alm_filters_{id}_category_args

This filter will adjust the arguments of a category query.

  • id: The unique filter ID

The following snippet will order a category filter listing by count in ascending order and render empty categories.

// [[ajax_load_more_filters id="almcats"]] 
function my_filters_category_args($args){
   // Adjust query $args.
   $args['order'] = 'ASC';
   $args['orderby'] = 'count';
   $args['hide_empty'] = false;
   return $args;	
}
add_filter( 'alm_filters_almcats_category_args', 'my_filters_category_args');
PHP

Note: The category query uses the core WordPress function get_terms – all accepted arguments can be used in this filter.

Tag: alm_filters_{id}_tag_args

This filter will adjust the arguments of a tag query.

  • id: The unique filter ID

The following code snippet will order a tag filter listing in ascending order.

// [[ajax_load_more_filters id="listing"]]
function my_filters_tag_args($args){
   // Adjust query $args.
   $args['order'] = 'ASC';
   return $args;	
}
add_filter( 'alm_filters_listing_tag_args', 'my_filters_tag_args');
PHP

Note: The tag query uses the core WordPress function get_terms – all accepted arguments can be used in this filter.

Taxonomy: alm_filters_{id}_{key}_args

This filter will adjust the get_terms query parameters used to retrieve the term list.

  • id: The unique filter ID
  • key: The target query parameter
    When filtering by taxonomy, the key parameter must be the taxonomy slug value.

The following code snippet will get the terms of the movie post type and order terms in ascending order by URL slug.

// [[ajax_load_more_filters id="movies"]]
function my_filters_actor_order( $args ){
   // Adjust get_terms query $args.
   $args['post_type'] = 'movie';
   $args['order'] = 'ASC';
   $args['orderby'] = 'slug';

   return $args;	
}
add_filter( 'alm_filters_movies_actor_args', 'my_filters_actor_order' );
PHP

Note: The taxonomy query uses the core WordPress function get_terms – all accepted arguments can be used in this filter.


« Back to Filters