HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: /var/www/html/insiders/wp-load/wp-content/plugins/breadly/block-library/query-result.php
<?php

/**
 * Registers the `gtm/query-result` block on the server.
 */
function gtm_register_block_query_result() {
	gtm_register_block_type( 'query-result', [
		'render_callback' => 'gtm_render_block_query_result',
	] );
}

add_action( 'init', 'gtm_register_block_query_result', 20 );

// Perform query in the same way as gtm_render_block_post_template()
function gtm_render_block_query_result( $attributes, $content, $block ) {
	if ( empty( trim( $content ) ) ) {
		return '';
	}

	// ORIGINAL from https://github.com/WordPress/gutenberg/blob/trunk/packages/block-library/src/post-template/index.php
	// Commits on Jan 13, 2022
	$page_key = isset( $block->context['queryId'] ) ? 'query-' . $block->context['queryId'] . '-page' : 'query-page';
	$page     = empty( $_GET[$page_key] ) ? 1 : (int) $_GET[$page_key];

	$query_args = gtm_build_query_vars_from_query_block( $block, $page );
	// Override the custom query with the global query if needed.
	$use_global_query = ( isset( $block->context['query']['inherit'] ) && $block->context['query']['inherit'] );
	if ( $use_global_query ) {
		global $wp_query;
		if ( $wp_query && isset( $wp_query->query_vars ) && is_array( $wp_query->query_vars ) ) {
			// Unset `offset` because if is set, $wp_query overrides/ignores the paged parameter and breaks pagination.
			unset( $query_args['offset'] );
			$query_args = wp_parse_args( $wp_query->query_vars, $query_args );

			if ( empty( $query_args['post_type'] ) && is_singular() ) {
				$query_args['post_type'] = get_post_type( get_the_ID() );
			}
		}
	}

	/* ME */$query_args = gtm_apply_post_template_query_args( $query_args, $block, $page, $attr );
	$query              = new WP_Query( $query_args );

	//////// End of gtm_render_block_post_template()

	if (  ( ! empty( $attributes['displayOnHasResult'] ) && $query->have_posts() )
		|| ( empty( $attributes['displayOnHasResult'] ) && ! $query->have_posts() ) ) {
		wp_reset_postdata();

		return sprintf(
			'<div %1$s>%2$s</div>',
			get_block_wrapper_attributes(),
			$content
		);

	} else {
		wp_reset_postdata();
		return '';
	}

}