diff --git a/includes/class-rest-post-controller.php b/includes/class-rest-post-controller.php index 1e3ef81..b986e8c 100644 --- a/includes/class-rest-post-controller.php +++ b/includes/class-rest-post-controller.php @@ -66,12 +66,12 @@ public function get_item_permissions_check( $request ) { */ public function get_collection_params() { return array( - 'uri' => array( + 'uri' => array( 'description' => __( 'Post slug to get post object by.', 'fuxt-api' ), 'type' => 'string', 'required' => true, ), - 'fields' => array( + 'fields' => array( 'description' => __( 'Additional fields to return. Comma separated string of fields.', 'fuxt-api' ), 'type' => array( 'string', 'array' ), 'items' => array( @@ -88,23 +88,31 @@ public function get_collection_params() { ), ), ), - 'children' => array( + 'children' => array( 'description' => __( 'Shorthand for fields[]=children&depth={depth}. Children depth value to include. Children field will be added to response. Only first grand child is returned.', 'fuxt-api' ), 'type' => 'integer', ), - 'per_page' => array( + 'per_page' => array( 'description' => __( 'Children per page count. Only works when children field exists', 'fuxt-api' ), 'type' => 'integer', ), - 'page' => array( + 'page' => array( 'description' => __( 'Children page number. Only works when children field exists', 'fuxt-api' ), 'type' => 'integer', ), - 'depth' => array( + 'paged' => array( + 'description' => __( 'Alias of page. Added for WordPress convention', 'fuxt-api' ), + 'type' => 'integer', + ), + 'offset' => array( + 'description' => __( 'Children offset. Only works when children field exists', 'fuxt-api' ), + 'type' => 'integer', + ), + 'depth' => array( 'description' => __( 'Children depth value. If this value is 2, first grand child is returned for each child. Only works when children field exists.', 'fuxt-api' ), 'type' => 'integer', ), - 'acf_depth' => array( + 'acf_depth' => array( 'description' => __( 'ACF field depth value.', 'fuxt-api' ), 'type' => 'integer', ), @@ -138,7 +146,7 @@ public static function get_item_schema() { 'description' => __( 'The excerpt for the post.' ), 'type' => 'string', ), - 'excerpt_raw' => array( + 'excerpt_raw' => array( 'description' => __( 'The raw excerpt data for the post. Returns empty strying if field data is empty.' ), 'type' => 'string', ), @@ -364,6 +372,8 @@ public function get_item( $request ) { $param_fields = array( 'per_page', 'page', + 'paged', + 'offset', ); $params['depth'] = isset( $request['depth'] ) ? $request['depth'] : ( isset( $request['children'] ) ? $request['children'] : 1 ); diff --git a/includes/class-rest-posts-controller.php b/includes/class-rest-posts-controller.php index 296318b..513b246 100644 --- a/includes/class-rest-posts-controller.php +++ b/includes/class-rest-posts-controller.php @@ -121,6 +121,14 @@ public function get_collection_params() { 'description' => __( 'Page number', 'fuxt-api' ), 'type' => 'integer', ), + 'paged' => array( + 'description' => __( 'Alias of page. Added for WordPress convention', 'fuxt-api' ), + 'type' => 'integer', + ), + 'offset' => array( + 'description' => __( 'Offset', 'fuxt-api' ), + 'type' => 'integer', + ), 'post_type' => array( 'description' => __( 'Post type', 'fuxt-api' ), 'type' => 'string', diff --git a/includes/utils/class-post.php b/includes/utils/class-post.php index 57b09f3..25bff74 100644 --- a/includes/utils/class-post.php +++ b/includes/utils/class-post.php @@ -81,7 +81,7 @@ public static function get_postdata( $post, $additional_fields = array(), $param ) ); - if ( ! isset($params['acf_depth'] ) ) { + if ( ! isset( $params['acf_depth'] ) ) { $params['acf_depth'] = 2; } @@ -131,6 +131,14 @@ function ( $sibling ) use ( $post ) { $query_params['paged'] = $params['page']; } + if ( isset( $params['paged'] ) ) { + $query_params['paged'] = $params['paged']; + } + + if ( isset( $params['offset'] ) ) { + $query_params['offset'] = $params['offset']; + } + $posts_query = new \WP_Query(); $children = $posts_query->query( $query_params ); @@ -390,6 +398,14 @@ public static function get_posts( $params, $additional_fields ) { $query_params['paged'] = (int) $params['page']; } + if ( isset( $params['paged'] ) ) { + $query_params['paged'] = (int) $params['paged']; + } + + if ( isset( $params['offset'] ) ) { + $query_params['offset'] = (int) $params['offset']; + } + if ( isset( $params['orderby'] ) ) { $query_params['orderby'] = $params['orderby']; }