Skip to content
This repository was archived by the owner on Feb 27, 2024. It is now read-only.

Commit 798a1d5

Browse files
committed
Fix post type check
1 parent fa7670c commit 798a1d5

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

api/wordpress/_global/getPostTypeArchive.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {initializeApollo} from '../connector'
22
import queryPostsArchive from '../posts/queryPostsArchive'
3+
import {postTypes} from './postTypes'
34

45
/**
56
* Retrieve post archive.
@@ -62,15 +63,17 @@ export default async function getPostTypeArchive(
6263
response.posts = await apolloClient
6364
.query({query, variables})
6465
.then((posts) => {
66+
const pluralType = postTypes[postType] ?? postType
67+
6568
// Set error props if data not found.
66-
if (!posts?.data?.[postType]?.edges) {
69+
if (!posts?.data?.[pluralType]?.edges) {
6770
response.error = true
68-
response.errorMessage = `An error occurred while trying to retrieve data for ${postType} archive.`
71+
response.errorMessage = `An error occurred while trying to retrieve data for ${pluralType} archive.`
6972

7073
return null
7174
}
7275

73-
return posts.data[postType].edges
76+
return posts.data[pluralType].edges
7477
})
7578
.catch((error) => {
7679
response.error = true

0 commit comments

Comments
 (0)