NextJS can't map through new content type

Hello prismic team!

I have created a new a document type called gated_content in my Prismic repo https://dd-sample-next-js-blog.prismic.io/documents/working~k=gated_content&l=en-us/ I am able to query for this content type in the API browser so I know the data is there: https://dd-sample-next-js-blog.prismic.io/api/v1/documents/search?ref=X-fc3BIAAMtlKxQ3&access_token=MTYwOTAzNDYyOTE3OS5YLWZkZFJJQUFNcGxLeGJV.77-977-9B--_ve-_vX_vv73vv73vv73vv71D77-977-977-9Ce-_ve-_vRgFQgbvv73vv73vv71a77-9GQvvv73vv73vv73vv70&q=[[at(document.type%2C+"gated_content")]]#format=json

I am able to see the data in my inspector and display individual pieces of content like so:

{gatedContentPosts.results[2].data.test}

In my blog page I am querying for this document type like so https://github.com/nikibrown/dd-nextjs-blog-ssr/blob/main/pages/index.js#L109

 const gatedContentPosts = await client.query([
	  Prismic.Predicates.at('document.type', 'gated_content')
	],
	{ orderings: '[my.post.date desc]' }
  )

And then trying to display this on my page like so https://github.com/nikibrown/dd-nextjs-blog-ssr/blob/main/pages/index.js#L30 :

{gatedContentPosts.results.map((gatedContentPost) => {
			<li key={gatedContentPost.uid}>
				<p>{RichText.render(gatedContentPost.data.title)}</p>
			</li>
		})}

When I try to map through the results nothing seems to happen. Not quite sure what I'm doing wrong. This is the exact method I'm using to display other types of content from prismic on this page.

You can view a live version of this site here: https://dd-nextjs-blog-ssr.nikibrown.vercel.app/

Thanks!

  • N

Hey Niki,

It seems there was and extra set of curly brackets in your query and your query option for the date was using the post still. Can you try the following?

 const gatedContentPosts = await client.query(
    Prismic.Predicates.at('document.type', 'gated_content'),
    { orderings: '[my.gated_content.date desc]' }
);

Thanks.

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