Filter
uncanny-automator-pro
automator_acf_post_type_posts_per_page
Filters the number of posts displayed for a specific post type within an Automator recipe's ACF field.
add_filter( 'automator_acf_post_type_posts_per_page', $callback, 10, 2 );
Description
Fires when determining the `posts_per_page` argument for ACF post type dropdowns in Uncanny Automator Pro. Developers can filter this to limit the number of posts displayed, useful for performance optimization on large sites. Defaults to 9999 to show all posts.
Usage
add_filter( 'automator_acf_post_type_posts_per_page', 'your_function_name', 10, 2 );
Parameters
-
$selected_post_type(mixed) - This parameter holds the maximum number of posts to retrieve for the specified post type.
-
$recipe_id(mixed) - This parameter represents the selected post type for which posts are being retrieved.
Return Value
The filtered value.
Examples
/**
* Filter the number of posts per page for a selected post type in Uncanny Automator's ACF integration.
*
* This example demonstrates how to conditionally increase the posts per page limit
* for specific post types or recipes when fetching posts for ACF fields within Uncanny Automator.
*
* @param int $posts_per_page The current posts per page limit. Defaults to 9999.
* @param string $selected_post_type The slug of the selected post type.
* @param int $recipe_id The ID of the current Uncanny Automator recipe.
*
* @return int The modified posts per page limit.
*/
add_filter( 'automator_acf_post_type_posts_per_page', function( $posts_per_page, $selected_post_type, $recipe_id ) {
// Increase the posts per page limit for the 'product' post type if it's part of recipe ID 123.
if ( 'product' === $selected_post_type && 123 === (int) $recipe_id ) {
return 50; // Show up to 50 products in this specific scenario.
}
// For any other post type or recipe, keep the default high limit to ensure all posts are fetchable.
// The default of 9999 is usually sufficient to fetch all available posts.
return $posts_per_page;
}, 10, 3 );
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/acf/helpers/acf-helpers-pro.php:118
public function acf_get_post_under_post_type() {
$list = array();
$selected_post_type = automator_filter_input( 'value', INPUT_POST );
$recipe_id = automator_filter_input( 'recipe_id', INPUT_POST );
$args = array(
'post_type' => $selected_post_type,
'posts_per_page' => apply_filters( 'automator_acf_post_type_posts_per_page', 9999, $selected_post_type, $recipe_id ),
'orderby' => 'title',
'order' => 'ASC',
);
$obj = get_post_type_object( $selected_post_type );
$post_type_name = esc_html_x( 'post', 'Advanced Custom Fields', 'uncanny-automator' );
if ( isset( $obj->labels->singular_name ) ) {
$post_type_name = $obj->labels->singular_name;
}
$query = new WP_Query( $args );
$list[] = array(
'value' => $selected_post_type,
/* translators: The post type singular label */
'text' => sprintf( esc_html_x( 'Any %s', 'Advanced Custom Fields', 'uncanny-automator' ), strtolower( $post_type_name ) ),
);
if ( $query->have_posts() ) :
while ( $query->have_posts() ) :
$query->the_post();
$list[] = array(
'value' => get_the_ID(),
'text' => get_the_title(),
);
endwhile;
wp_reset_postdata();
endif;
wp_send_json( $list );
}