#Get post by slug without info about collection

10 messages · Page 1 of 1 (latest)

jolly stratus
#

Hi, I'm trying to get a post in a content collection by slug. Is it possible?

jolly stratus
ivory aspen
#

did you see the link I posted ? getEntryBySlug()
I think you need to explain a bit more otherwise, maybe post a non functional example of how you want it with expected result.

modern otter
ivory aspen
#

but why would someone mix slug of multiple collections on the same url ? when you get the slug you usually know the collection, otherwise something's fishy.

modern otter
#

not sure what the OP is doing. maybe a top-level [slug].astro file. but yeah, iterating over will be the only way to do it

ivory aspen
#

true. that way also you mix e.g. authors and books on the same path/slug (not much sense), you also have to ensure the slug is unique across all collections. Not a recommended design.

jolly stratus
ivory aspen
#

for that Otterlord solution of looping through all collections and check result of getEntryBySlug() should work for you right ? did you try that ?