Home / Archive / Multipost Query Loop
Duplicate Snippet

Embed Snippet on Your Site

Multipost Query Loop

This code snippet adds the ability to add multiple posts to the Generate Blocks Query Loop

Joe McCorison PRO
<10
Code Preview
php
<?php
add_filter( 'generateblocks_query_loop_args', function( $query_args, $attributes ) {
	$attributesArray = array_column($attributes['htmlAttributes'], 'value', 'attribute');
		
	if (isset($attributesArray['data-posts'])) {
		$posts = explode(',', $attributesArray['data-posts']) ?? [];
		return array_merge( $query_args, array(
          'post_type' => $posts,
        ) );
    }
    return $query_args;
}, 10, 2 );

Comments

Add a Comment