Are you a GenerateCustomer?

Do you have an active GP Premium or GenerateBlocks Pro license key?

Create a GenerateSupport account for GeneratePress and GenerateBlocks support in one dedicated place.

Create an account
Already have a GenerateSupport account? Login

Just browsing?

Feel free to browse the forums. Support for our free versions is provided on (GeneratePress, GenerateBlocks).

Want to become a premium user? Learn more below.

query loop to show posts and pages

  • I’m sure this is a simple one but I cant find the answer.

    Can I use a query loop to show results from POSTS and PAGES. Both share common taxonomy ( categories)


  • Hi there,

    yes, but for now you have to use some PHP.

    1. Add this PHP Snippet:

    add_filter( 'generateblocks_query_loop_args', function( $query_args, $attributes ) {
      if ( 
        ! is_admin() &&
        ! empty( $attributes['className'] ) && 
        strpos( $attributes['className'], 'posttype-query' ) !== false
      ) {
        $query_args[ 'post_type' ] = array('post', 'page');
      return $query_args;
    }, 10, 2 );

    2. In the Query Loop, select the Grid Block and give it a CSS class of: posttype-query

  • Thats awesome. works perfectly, many thanks.

  • You’re welcome

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