diff --git a/src/runtime/composables/useWpPost.ts b/src/runtime/composables/useWpPost.ts index 78bb9c7..f2fe61d 100644 --- a/src/runtime/composables/useWpPost.ts +++ b/src/runtime/composables/useWpPost.ts @@ -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', 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) {