Query by type and custom field

Hi,

New to prismic and seems very straight forward so far!

I am however struggling to query a document type by a field. Is this possible please? I don't want this to be filtered by content relationship, but instead of the object(s) itself.

Eg: Below I wish to find all the documents where the type is "Blog" and where the field "categories" have the value(s) "One" or "Two".

@response = api.query([ Prismic::Predicates.at("document.type", "blog"), Prismic::Predicates.at("blog.categories", ["One", "Two" ])] )

Thanks,

Chris

Hi Chris,

Welcome to the community!

I think this might just be a small syntax error, it should be my.blog.categories

@response = api.query([ Prismic::Predicates.at("document.type", "blog"), Prismic::Predicates.at("blog.categories", ["One", "Two" ])] )

Thanks.

Hi Phil,

Thank you for the warm welcome and your response.

I've not had any luck with the code provided, do you know if the field has to be of a certain type or if any can be used?

Thanks,

Chris

Hi Phil,

Apologies, this is now working. Thank you very much for your help!

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.