• Resolved mviana2k

    (@mviana2k)


    I have multiple custom posts types and want the homepage to display posts from all types, ordered by date of posting. How can I create query loops that retrieve multiple posts?

Viewing 3 replies - 1 through 3 (of 3 total)
  • 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/

    Thread Starter mviana2k

    (@mviana2k)

    It works.
    Thank you!

    Plugin Support ying

    (@yingscarlett)

    You are welcome ? ??

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Multiple post type in one query loop’ is closed to new replies.