“Plugin API/Filter Reference/post limits”的版本间的差异

来自WordPress中文文档
跳转至: 导航搜索
 
(1个版本)
 
(没有差异)

2013年8月2日 (五) 04:22的最新版本

Description

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

Usage

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

Examples

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.

Notes

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