From c1298d9891327fa4681a99430f8ff7962562a579 Mon Sep 17 00:00:00 2001 From: Etienne Moureton Date: Fri, 15 Mar 2024 22:18:30 +0100 Subject: [PATCH] fix --- src/runtime/composables/useWpPost.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) 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) {