function posts_limit_fn($limit, $query, $custom_limit = ''){
if($custom_limit !== ''){
return $custom_limit;
}
return $limit;
}
this piece of code is executed into an AJAX function add_action('wp_ajax_search_query', 'search_query');
$queryString = array( 's' => $searchTerm, 'cat' => $categoriesIDs, 'post__not_in' => array($excludedPost));
if($queryString != ''){
add_filter('post_limits', 'posts_limit_fn',10, 3);
$custom_limit = 'LIMIT 0,4';
apply_filters('post_limits', '', '', $custom_limit);
$query = new WP_Query($queryString);
}
For some kinda of reasons the apply_filters
doesn't work so the query is returning all posts. What would be the problem ?
UPDATE:
Seems that If I have something like this :
function posts_limit_fn($limit,$query,$custom_limit = ''){
echo $custom_limit.">>>>>>>";
if($custom_limit !== ''){
return 'LIMIT 0,3';
}
return $limit;
}
the output is LIMIT 0,4>>>>>>>>>LIMIT 0,10>>>>>>>>>post1,post2,post3