Homepage Query Loop

  • Hi,
    My homepage has a query loop section featuring 3 articles. I want to inlcude one page, and 2 posts under a section. But I only see the toggle Select post type to switch to posts , or pages exclsuively. How can I customize this.

    Thanks

  • Hello,

    You could include both Posts and Pages in the query loop, then add an Include posts parameter and select the posts and page you want.

  • thanks for your response. Not sure I understand

    under query loop post type I only see the options say:
    posts, pages, styles simple galleries.

    its currently set to pages (see screenshot below)

    ‘You could include both Posts and Pages in the query loop’ I dont see how to do that because its making me choose either one or the other. if i select pages only pages show up not posts. and vice versa.

  • Hello,

    You can select both, just click in the dropdown and select Posts too.

    Query loop with pages and posts

  • For some reason, it’s only letting me do one or the other not both, sharing access

  • Hi there,

    It looks like you’re still using the V1 Query Loop block, which only allows selecting a single post type from the UI.

    Would it be possible for you to switch to the V2 Query block? If that’s not an option, you would need to use a custom snippet to query multiple post types.

    Let me know.

  • Please share how to switch to v2, and what this entails. Will this mess up my currrent layout.

  • Your current layout will stay as it is, the existing v1 blocks will stay as v1.

    To switch to v2, go to generateblocks > settings, toggle off the v1 option.

    For more info: https://learn.generatepress.com/blocks/block-guide/generateblocks-1-x-to-2-0/#ver2

  • Thanks- my Dashboard > GenerateBlocks > Settings
    Does not show the v1 toggle

  • That means your site is already using the V2 blocks, but the current layout is still built with V1 blocks—likely because the site was imported when it was still on V1.

    In this case, you’ll need to recreate the Query block layout using V2, then redesign and reconfigure the dynamic data. If that feels like too much work, alternatively you can use a snippet-based solution to achieve it while staying on V1, as outlined here:

    https://docs.generateblocks.com/article/add-multiple-post-types-in-one-query-loop/

  • Hi,
    I added advanced-query to the grid (for Top sights) and the code in code snippets. I’m still not seeing a difference. Did I do this right?

  • Hi,

    First of all, remove the INCLUDE POSTS parameter from your query loop.

    Then, you can modify the PHP snippet to target specific posts and pages by their IDs. Here’s an updated version:

    add_filter( 'generateblocks_query_loop_args', function( $query_args, $attributes ) {
        if ( 
            ! is_admin() &&
            ! empty( $attributes['className'] ) && 
            strpos( $attributes['className'], 'advanced-query' ) !== false
        ) {
            $query_args['post_type'] = array( 'post', 'page' );
            $query_args['post__in']  = array( 12, 34, 56 ); // Replace with your post/page IDs
            $query_args['orderby']   = 'post__in';
        }
        
        return $query_args;
    }, 10, 2 );

    Replace 12, 34, 56 with the IDs of the posts and pages you want to display. The orderby line ensures they appear in the order you list them.

    To find a post or page ID, go to Posts > All Posts (or Pages > All Pages), hover over the title, and look at the URL in your browser’s status bar — you’ll see something like post=123. That number is the ID.

  • Thank you! the 3 (pages/posts) are now appearing under top sights.

    Note: is it normal that not all 3 of them appear in the backend but only on website.

  • Note: is it normal that not all 3 of them appear in the backend but only on website.

    Yes, that’s expected behavior. The snippet doesn’t apply in the editor; it only takes effect on the frontend.

  • Thank you

  • No problem!

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