[Support request] CPT query block within a page section?!

Home Forums Support [Support request] CPT query block within a page section?!

Home Forums Support CPT query block within a page section?!

Viewing 13 posts - 1 through 13 (of 13 total)
  • Author
  • #1963813

    I didn’t find this topic, if it exhists, please move the question there.

    On my homepage I want to have a section that displays several CPTs, let’s say, recently published ones.

    As far as I understand, element (block) depends on its location in CPT > Archive, or in blog if post_type is post, to loop over content of the query. This does not help as it limits the loop to archive pages, preventing the possibility of sections and queries in pages.

    I also tried to use headline, within wordpress core query block to display CPT custom fields data in loops, doesn’t work.

    Is a homepage like this possible with GP premium https://kulturforum-zagreb.org/ or like this https://apuri.hr/ ?


    A feature request? Can you provide a dynamic content block in the context of GenerateBlocks (for premium users) so that it can be used outside of elements context? It seems as a basic thing nowadays.

    To understand recursion, you first have to understand recursion.

    Customer Support

    Hi Elvis,

    For now, you can try using WP Show Posts to display a query loop for CPTs. https://wpshowposts.com/

    But in the future, GenerateBlocks and WP Show Posts are set to merge.

    Tom plans to merge the 2 plugins by adding a post grid block to GenerateBlocks, effectively turning WPSP into a block.

    But we don’t have ETA for this at the moment. πŸ˜€

    A wise man once said:
    "Have you cleared your cache?"


    Hi Elvin,
    well that’s a minimal name difference. πŸ™‚

    Thank you for a quick reply.

    I am trying to avoid shortcodes in gerneal, however since this is something that would be merged into the product in the future I would maybe even use it if there weren’t a following problem.

    The plugin misses a feature that is kind of the point of my problem. It does not fully support CPTs. Post meta is limited to standard post meta. I cannot choose to display, or orderby custom fields. Let’s say I want to display book cards, I cannot display book author name in my card with the plugin.

    Is there a way to pull what I build as elements with shourcodes into a page. I think I know your answer, but grabing onto a straw here. I hear blocksy pro can do this.

    Alternatively, can you recomend (preferably gutenberg way) a 3rd party plugin that would add this for now missing functionality, following a GP philosophy of lean, accessible code?


    To understand recursion, you first have to understand recursion.

    Customer Support

    Hi there,

    Block elements are simply templates that can be Hooked into other places, such as a custom loop.
    Breaking it down you would need to create a shortcode that:

    a. Sets the query args
    b. outputs a loop
    c. includes a hook inside that loop

    Heres a shortcode i made to do that for a custom build as an interim solution until GB has a query block:


    The shortcode it create is: [db_display_custom_post_loop]
    The hook name it outputs inside the loop is: db_custom_post_loop

    For the Block Element, you would set the Hook to Custom Hook, and add the above to the field provided.
    The Display Rules can be set to the Entire site as it will only get called where that hook is output.

    You will need to add some Custom CSS to create the grid however.

    Something to play with.


    Hi David,

    thanks for the answer.
    This looks nice. A couple of questions though.

    Why hook? I am allready working on a shortcode for displaying links to documents, so I taught I can tweak this to do more .. here https://gist.github.com/thisbit/baa25d414af2c81f1f5615930c581f38

    Why would a hook be useful for a situation that is trying to be used instead a GP query block?

    Additionaly, performance wise, what do you think, would it be better to have dedicated separate shortcodes, or only one? Let’s say, one when someone wants to output a grid of CPTs with featured image etc, another when someone wants a list of recent articles, another for when someone wants to list events coming up… or would it be better to create one, and then let user tweak their query via shotcode params, which in turn also spits different markup, fields etc?

    I beleive for users it would be better to have one, and tweak with params, I am just wondering about performance.

    Thanks a lot.

    To understand recursion, you first have to understand recursion.

    Customer Support

    The purpose of the Hook is for you to attach your Block Element ( Type: Hook ) to output your content.
    Aside from the limited design options with the core Query Block, you don’t have access to custom post_meta.
    So my method allows you to build your custom template in Block Element and output it in your custom loop shortcode.

    Shortcodes – one vs many – really depends … A few simple shortcodes will probably be more performant then a single shortcode that has LOTS of params/queries/conditions running. But i think the difference would be negligible. I would go with whats best for the end user to work with.


    Oh, nice, didn’t think about it this way at all.
    For me hooks are these permanent spots within the wp system, not mooving about. πŸ™‚

    Hmm. This way I would be kinda able to design the CPT template visually in the coresponding block element with GP, but then insert it anywhere I want via the shortcode.

    Thanks so much.

    To understand recursion, you first have to understand recursion.

    Customer Support

    Glad to be of help.

    And thanks for the 5 stars !! much appreciated.



    You can also take a look at PostX. It allows you to display different kinds of posts (and CPT) grids that are quite customizable (with plenty of query settings).

    But well, if you want to keep a low number of plugins, definitely go with David’s suggestion.


    Hi David

    Sorry picking this thread up again as I’m using your solution on a site I’m building currently as stop gap until the query block arrives. I’m using the code snippet you shared above to output a custom post type listing for some FAQs on some pages.

    I’ve added the code snippet via the Snippets plugin and created a block element content template assigned to the custom hook in the snippet, but the content template isn’t being output.

    I can see the rest of the code from the shortcode is though so I know the shortcode has registered OK and is working.

    If I have the above snippet activated and the block element registered to the correct custom hook which I appear to shouldn’t it just work? By the way I’ve also set the display rules for the element to entire site, so I don’t think it is that either. Not sure if I’ve missed a step somewhere?

    Any help would be much appreciated.


    Customer Support

    Hi there,

    the code snippet works for the standard Posts, you would need to update the query args in that snippet to include your custom post type.


    Just dropping in to say a big “thanks” for this solution, David! Exactly what I needed.
    For anyone that doesn’t want to deal with the code, the plugin mentioned on this thread, PostX, is a good one with lots of flexibility.

    Customer Support

    Hi Lucy – thats really kind of you – glad it was of use πŸ™‚

Viewing 13 posts - 1 through 13 (of 13 total)
  • You must be logged in to reply to this topic.