We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
I'm trying to order a GROQ query dynamically by passing an $order variable.
$order
Hardcoding does work
const query = groq`{"BlogPosts": *[_type=='blog_post'] | order(publishedAt desc)}`; const { data, status } = await useSanityQuery(query)
Passing a variable does not work. The ordering is just ignored and the results are returned without ordering
const query = groq`{"BlogPosts": *[_type=='blog_post'] | order($order desc)}`; const { data, status } = await useSanityQuery(query, { 'order': 'publishedAt', });
The same when passing the order field as a string. This does not work:
const query = groq`{"BlogPosts": *[_type=='blog_post'] | order('publishedAt' desc)}`; const { data, status } = await useSanityQuery(query)
Am I passing the order variable in a wrong format or is this not possible with this module?
The text was updated successfully, but these errors were encountered:
I haven't tested your query but what jumped at me is that you are not using a template literal for the query like:
const query = groq`{"BlogPosts": *[_type=='blog_post'] | order($order desc)}`; const { data, status } = await useSanityQuery(query, { 'order': 'publishedAt', });```
Sorry, something went wrong.
I haven't tested your query but what jumped at me is that you are not using a template literal for the query like: const query = groq{"BlogPosts": *[_type=='blog_post'] | order($order desc)}; const { data, status } = await useSanityQuery(query, { 'order': 'publishedAt', });```
const query = groq{"BlogPosts": *[_type=='blog_post'] | order($order desc)}; const { data, status } = await useSanityQuery(query, { 'order': 'publishedAt', });```
{"BlogPosts": *[_type=='blog_post'] | order($order desc)}
Thx for the response. However, this was just a copy paste error. I've updated the questions to include the correct backticks.
No branches or pull requests
I'm trying to order a GROQ query dynamically by passing an
$order
variable.Hardcoding does work
Passing a variable does not work. The ordering is just ignored and the results are returned without ordering
The same when passing the order field as a string. This does not work:
Am I passing the order variable in a wrong format or is this not possible with this module?
The text was updated successfully, but these errors were encountered: