Created
August 13, 2018 19:15
-
-
Save daler445/04d32bf82db70ddf3d773bb0f0b28193 to your computer and use it in GitHub Desktop.
Изменения лимита per_page (1-100) и изменения значения по умолчанию per_page (10) в wordpress rest api
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* post type: mytype (custom) */ | |
/* | |
*change limit of 100 per page | |
*изменения лимита | |
*/ | |
add_filter( 'rest_mytype_collection_params', 'limit_change_ph_gos_per_page', 10, 1 ); | |
function limit_change_ph_gos_per_page( $params ) { | |
if ( isset( $params['per_page'] ) ) { | |
$params['per_page']['maximum'] = 200; | |
} | |
return $params; | |
} | |
/* | |
*change default per page | |
*изменения значения по умолчанию | |
*/ | |
add_filter( 'rest_endpoints', function( $endpoints ){ | |
if ( ! isset( $endpoints['/wp/v2/mytype'] ) ) { | |
return $endpoints; | |
} | |
$endpoints['/wp/v2/mytype'][0]['args']['per_page']['default'] = 20; | |
return $endpoints; | |
}); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment