Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Etienne Moureton committed Mar 15, 2024
1 parent 5f7c496 commit c1298d9
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/runtime/composables/useWpPost.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,19 @@ import type { Post } from '../types'
interface Options {
type?: string,
id?: number | string,
slug?: string
}

const useWpPost = async ({ type = 'posts', id }: Options = {}) => {
const useWpPost = async ({ type = 'posts', id, slug }: Options = {}) => {
const route = useRoute()
const query = id || route.path.substring(1)
const query = id ? id : slug || route.params.slug

const { data, error } = await useAsyncData<Post>('post', async () => {
const { apiEndpoint } = useRuntimeConfig().public.wordpress

const url = id ? `${apiEndpoint}/${type}/${id}` : `${apiEndpoint}/${type}?slug=${query}`

return $fetch(`${apiEndpoint}/${type}/${query}`)
return $fetch(url)
})

if(error.value) {
Expand Down

0 comments on commit c1298d9

Please sign in to comment.