Plugin API/Filter Reference/post limits

Zhuozuran讨论 | 贡献2013年8月2日 (五) 04:22的版本 (1个版本)
(差异) ←上一版本 | 最后版本 (差异) | 下一版本→ (差异)
跳转至: 导航搜索


This filter applies to the queries LIMIT clause before the query is sent to the database allowing you to define a new query LIMIT.


%%%<?php add_filter( 'post_limits', 'my_post_limits' ); ?>%%%


add_filter( 'post_limits', 'my_post_limits' );
function my_post_limits( $limit ) {
    if ( is_search() ) {
        return 'LIMIT 0, 25';
    return $limit;

This will allow your query to return 25 results only for search page, all other queries will continue to return the default value.


You can return null to remove the LIMIT clause from the query allowing you to return all results. This will however set $wp_query->found_posts to be 0.

Return to Plugin API/Filter Reference