Filter uncanny-automator-pro

automator_pro_post_loop_date_filter_posts_per_page

Filters the number of posts to display in the Automator Pro post loop by date.

add_filter( 'automator_pro_post_loop_date_filter_posts_per_page', $callback, 10, 1 );

Description

Filters the number of posts retrieved when a date condition is applied to a post loop. Developers can adjust the default 99999 limit to control how many posts are considered in the date filter. This hook fires after the `date_query` arguments are prepared.


Usage

add_filter( 'automator_pro_post_loop_date_filter_posts_per_page', 'your_function_name', 10, 1 );

Parameters

$post_type (mixed)
This parameter represents the default number of posts to retrieve when filtering posts by date, which can be modified by custom code.

Return Value

The filtered value.


Examples

/**
 * Example of how to filter the 'automator_pro_post_loop_date_filter_posts_per_page' hook.
 *
 * This example demonstrates how to conditionally change the 'posts_per_page' value
 * based on the post type. If the post type is 'recipe', it limits the posts per page
 * to 10; otherwise, it uses the default value provided by the filter.
 *
 * @param int   $posts_per_page The default posts per page value (99999 in this context).
 * @param array $args           An array containing 'post_type' and 'date_query'.
 *
 * @return int The modified posts per page value.
 */
add_filter( 'automator_pro_post_loop_date_filter_posts_per_page', function( $posts_per_page, $args ) {

	// Check if the 'post_type' is set in the arguments.
	if ( isset( $args['post_type'] ) ) {
		$post_type = $args['post_type'];

		// If the post type is 'recipe', limit the posts per page to 10.
		if ( 'recipe' === $post_type ) {
			return 10;
		}
	}

	// Otherwise, return the original posts_per_page value.
	return $posts_per_page;

}, 10, 2 ); // 10 is the priority, 2 is the number of arguments accepted.

Placement

This code should be placed in the functions.php file of your active theme, a custom plugin, or using a code snippets plugin.


Source Code

uncanny-automator-pro/src/integrations/wp/loop-filters/wp-post-date-meets-condition.php:282

break;
			case 'day':
				$date_query['day'] = date( 'd', strtotime( $date ) );
				break;
		}

		// Allow filter posts per page.
		$posts_per_page = apply_filters(
			'automator_pro_post_loop_date_filter_posts_per_page',
			99999,
			array(
				'post_type'  => $post_type,
				'date_query' => $date_query,
			)
		);

Scroll to Top