Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 18 additions & 8 deletions includes/class-rest-post-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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',
),
Expand Down Expand Up @@ -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',
),
Expand Down Expand Up @@ -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 );
Expand Down
8 changes: 8 additions & 0 deletions includes/class-rest-posts-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
18 changes: 17 additions & 1 deletion includes/utils/class-post.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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 );

Expand Down Expand Up @@ -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'];
}
Expand Down