From a3040420c02f538fff511e042e805a741c90cd24 Mon Sep 17 00:00:00 2001 From: Tetrakern <26898880+Tetrakern@users.noreply.github.com> Date: Sun, 19 Feb 2023 16:27:46 +0100 Subject: [PATCH] Fix chapter count in API --- API.md | 2 +- includes/functions/_api.php | 7 ++----- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/API.md b/API.md index 0bb86c67..1c7735b0 100644 --- a/API.md +++ b/API.md @@ -2263,7 +2263,7 @@ The following schema defines all fields that can exist within the response, excl | url `string` | Root URL of the targeted site. In case you forgot or want to make sure. | language `string` | Language code of the _site_, not necessarily stories or chapters. | storyCount `integer` | Total number of published and visible stories. -| chapterCount `integer` | Total number of published and visible chapters. +| chapterCount `integer` | Total number of published chapters, including those marked as non-chapter. | lastPublished `integer\|null` | Unix timestamp of the last published story (GMT). | lastModified `integer\|null` | Unix timestamp of the last modified story (GMT). | stories `object\|null` | Paginated collection of story nodes, ordered by publishing date. See **Story** endpoint. diff --git a/includes/functions/_api.php b/includes/functions/_api.php index 965cc512..2c5dd3b8 100644 --- a/includes/functions/_api.php +++ b/includes/functions/_api.php @@ -71,7 +71,7 @@ if ( ! function_exists( 'fictioneer_api_get_story_node' ) ) { $node['words'] = intval( $data['word_count'] ); $node['ageRating'] = $data['rating']; $node['status'] = $data['status']; - $node['chapterCount'] = $data['chapter_count']; + $node['chapterCount'] = intval( $data['chapter_count'] ); $node['published'] = get_post_time( 'U', true, $story_id ); $node['modified'] = get_post_modified_time( 'U', true, $story_id ); $node['protected'] = post_password_required( $story_id ); @@ -365,7 +365,7 @@ if ( ! function_exists( 'fictioneer_api_request_stories' ) ) { $graph['url'] = get_home_url( null, '', 'rest' ); $graph['language'] = get_bloginfo( 'language' ); $graph['storyCount'] = intval( wp_count_posts( 'fcn_story' )->publish ); - $graph['chapterCount'] = 0; + $graph['chapterCount'] = intval( wp_count_posts( 'fcn_chapter' )->publish ); // Stories if ( ! empty( $stories ) ) { @@ -377,9 +377,6 @@ if ( ! function_exists( 'fictioneer_api_request_stories' ) ) { // Get node $node = fictioneer_api_get_story_node( $story->ID, FICTIONEER_API_STORYGRAPH_CHAPTERS ); - // Count chapters - $graph['chapterCount'] = $graph['chapterCount'] + $node['chapterCount']; - // Add to graph $graph['stories'][ $story->ID ] = $node;