Fix chapter count in API

This commit is contained in:
Tetrakern 2023-02-19 16:27:46 +01:00
parent 7ce7fb6cf6
commit a3040420c0
2 changed files with 3 additions and 6 deletions

2
API.md
View File

@ -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.

View File

@ -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;