Using Query Loop with Custom Post Type

admin2025-01-07  5

I have a Custom Post Type (CPT) named "Events", and I want to add a Query Loop on my front page that displays the upcoming events that my website visitors may want to participate in. On the "Post Type" setting of the Query Loop, I only saw two choices: "Post" and "Page". However, I heard Query Loop can be used with CPT too and I saw a YouTube video showing a Query Loop with CPT options (screenshot below).

The video itself does not cover how to apply CPT on Query Loop, so I tried googling for some tutorials. I found this article which may contain the solution I need; the thing is it requires NodeJS which I am not familiar of.

So I wonder if there is any alternative solution to this. Perhaps PHP code that does not require NodeJS? Or a certain plugin that I can install? Thank you in advance!

I have a Custom Post Type (CPT) named "Events", and I want to add a Query Loop on my front page that displays the upcoming events that my website visitors may want to participate in. On the "Post Type" setting of the Query Loop, I only saw two choices: "Post" and "Page". However, I heard Query Loop can be used with CPT too and I saw a YouTube video showing a Query Loop with CPT options (screenshot below).

The video itself does not cover how to apply CPT on Query Loop, so I tried googling for some tutorials. I found this article which may contain the solution I need; the thing is it requires NodeJS which I am not familiar of.

So I wonder if there is any alternative solution to this. Perhaps PHP code that does not require NodeJS? Or a certain plugin that I can install? Thank you in advance!

Share Improve this question asked Aug 22, 2023 at 8:02 mawgumelarmawgumelar 111 bronze badge 3
  • is e.g. show_in_rest set as true when you define your cpt? – birgire Commented Aug 22, 2023 at 9:21
  • 1 @birgire Wow thank you very much! I just typed in show_in_rest and set it as true, and now it works! :D – mawgumelar Commented Aug 23, 2023 at 2:16
  • Good to hear it worked. I posted it as an answer. – birgire Commented Aug 23, 2023 at 9:24
Add a comment  | 

1 Answer 1

Reset to default 0

The post-type dropdown in the Query Loop block is populated with data from the REST API endpoint:

/wp-json/wp/v2/types

so we have to make sure the public custom post type is registered with show_in_rest as true for it to be included within that data.

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1736260219a649.html

最新回复(0)