Filter Hooks

The following core Ajax Load More hooks are available to modify query arguments and display settings.


Query Filters

alm_query_args_{id}

The alm_query_args_{id} filter modifies WP_Query arguments by Ajax Load More instance ID.

// functions.php
function my_movie_listing( $args, $id ){
	// [ajax_load_more id="movie_listing"]

	$args['post_type'] = 'movie';
  $args['tax_query'] = array(
    array(
      'taxonomy' => 'genre',
      'field' => 'slug',
      'terms'  => 'comedy'
    ),
  );
  return $args;
}
add_filter( 'alm_query_args_movie_listing', 'my_movie_listing', 10, 2 );
PHP

This filter requires the following 2-step process:

  1. Set Unique ID
    Create a unique ID for the Ajax Load More instance by setting a value for the id parameter.
    e.g. [ajax_load_more id="your_alm_id"]
  2. Add Hook
    Create the custom hook for this instance by appending the unique ID to the filter name.
    add_filter(‘alm_query_args_your_alm_id’, ‘my_function_name’);

When is this filter useful?
This filter is useful for advanced users who prefer writing custom queries vs working with shortcode parameters.

Note: Never modify the offset or paged query parameters – these parameters must be set within the core plugin or results may be undesired.

Dynamic Query Parameters

The following snippet appends a Meta Query to fetch events by custom field date.

The idea is that this becomes an ever-present query on the specific Ajax Load More instance.

// functions.php 
function my_alm_events( $args, $id ) { 
   // [ajax_load_more id="event_listing" ... ]

   $default_query = [
      'key'  => 'start_date',
      'value'   => date( 'Y-m-d' ),
      'compare' => '>=',
      'type'    => 'DATE'
   ];

   if ( isset( $args[ 'meta_query' ] ) && $args[ 'meta_query' ] ) {
      // Append to existing meta_query.
      $args['meta_query'][] = $default_query;
   } else {
      // meta_query does not exist.
      $args['meta_query'] = [ $default_query ];
   }
   return$args;
}
add_filter( 'alm_query_args_event_listing', 'my_alm_events' );
PHP

Parsing Querystrings

Build a custom query based on querystring parameters by parsing the URL directly inside the alm_query_args filter.

The following snippet retrieves a category value from a querystring and adds the category parameter to the $args array.

// functions.php
function my_alm_query_args( $args ){
   // https://website.com/?category=design
   
   $url = $_SERVER["HTTP_REFERER"]; // Get referring URL.
   $parts = parse_url($url); // Parse the URL.
   parse_str( $parts['query'], $querystring ); // Get the querystring.
	
   if ( $querystring && $querystring['category'] ){
         $args['category'] = $querystring['category']; // Add category to $args array.
   }
   return $args;
}
add_filter( 'alm_query_args_default', 'my_alm_query_args' );
PHP

alm_query_after_{id}

The alm_query_after_{id} filter can be used to modify the results of a WP_Query by Ajax Load More instance ID.

// [ajax_load_more id="default"]
function my_alm_query_after( $query ){
	usort($query->posts, function( $a, $b ) {
	  return strnatcasecmp( $a->post_name,$b->post_name );
	});
	return $query;
}
add_filter( 'alm_query_after_default', 'my_alm_query_after' );
PHP

alm_allow_future_posts

This filter is used to allow for future posts to be displayed for all users. By default, ALM does not allow for future posts to be displayed for non-admin users.

add_filter( 'alm_allow_future_posts', '__return_true' );
PHP

alm_debug

This filter is used to display the Ajax Load More WP_Query arguments in the browser console. Debug data will be returned in a unique entry labeled alm_debug in the browser console.

add_filter( 'alm_debug', '__return_true' );
PHP

alm_disable_noscript_{id}

This filter will remove the dynamic <noscript/> tags generated by the Filters and SEO add-ons.

// [ajax_load_more id="default"]
add_filter( 'alm_disable_noscript_default', '__return_true' )
PHP

You can globally disable <noscript/> functionality across all Ajax Load More instances.

add_filter( 'alm_disable_noscript_', '__return_true' )
PHP

alm_repeater_path

The alm_repeater_path filter can be used to change the Repeater Template directory path. By default, Repeater Templates are saved in an alm_templates folder located in the wp-content/uploads directory.

// functions.php
add_filter( 'alm_repeater_path', function() {
	return get_stylesheet_directory() . '/my-alm-templates';
});
PHP

Display Options

alm_after_container

This filter adds content or HTML after the Ajax Load More container.

add_filter( 'alm_after_container', function(){
	return '<p><a href="/work">View All Work</a></p>';
});
PHP

alm_after_button

This filter adds content after the load more .alm-button-wrap button container.

add_filter( 'alm_after_button', function(){
   return '<hr/>';
});
PHP

alm_before_button

This filter adds content before the load more .alm-button-wrap button containers.

add_filter( 'alm_before_button', function(){
	return '<hr/>';
});
PHP

alm_before_container

This filter adds content or HTML before the Ajax Load More container.

add_filter( 'alm_before_container', function(){
	return '<div>' . esc_attr__( 'Recent Blog Posts', 'framework' ) . '</div>';
});
PHP

alm_button_label

This filter modifies the default Older Posts label on the Ajax Load More button.

// functions.php
add_filter( 'alm_button_label', function(){
	return esc_attr__( 'Get More Posts!', 'framework' );
});
PHP

alm_button_wrap_classes

This filter adds custom HTML classes to the load more button container.

// functions.php
add_filter( 'alm_button_wrap_classes', function(){
   return "my-10 rounded-sm bg-black text-white";
});
PHP

alm_settings

This filter overrides the global Ajax Load More plugin settings.

add_filter( 'alm_settings', function( $options ) {
	$options['_alm_btn_color'] = 'infinite';
	return $options;
});
PHP

alm_shortcode_defaults

This filter sets global defaults for Ajax Load More parameters. These can be overwritten using the shortcode or the alm_render implementation method.

add_filter( 'alm_shortcode_defaults', function() {
	return [
		'wrapper_classes' => 'woocommerce',
		'css_classes'     => 'products columns-2',
		'posts_per_page' => '10'
	];
});
PHP

alm_speed

This filter adjusts the global transition speed of Ajax Load More elements.

add_filter( 'alm_speed', function(){
	return 100; // 250
});
PHP

Admin Filters

alm_mask_license_keys

Mask the Ajax Load More license keys on the license plugin admin screen.

add_filter( 'alm_mask_license_keys', '__return_true' );
PHP