Multiple post type in one query loop

[ad_1]

Plugin Support
ying

(@yingscarlett)

Hi there,

It will require some PHP code.

  1. Add a css class to the Grid block nested in the query loop block, eg.multi-query :https://wordpress.com/support/wordpress-editor/adding-additional-css-classes-to-blocks/
  2. Add this PHP code, and change this line array('post', 'page', 'cpt-slug-1', 'cpt-slug-2');to match your post types.
add_filter( 'generateblocks_query_loop_args', function( $query_args, $attributes ) {
	if ( 
        ! is_admin() &&
        ! empty( $attributes['className'] ) && 
        strpos( $attributes['className'], 'multi-query' ) !== false
	) {
        // pass meta_query parameter
        $query_args[ 'post_type' ] = array('post', 'page', 'cpt-slug-1', 'cpt-slug-2');
	}
	
	return $query_args;
}, 10, 2 );

Adding PHP: https://docs.generatepress.com/article/adding-php/

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer