File tree Expand file tree Collapse file tree
tests/phpunit/tests/blocks Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -2704,6 +2704,7 @@ function wp_migrate_old_typography_shape( $metadata ) {
27042704 * @since 6.1.0 Added `query_loop_block_query_vars` filter and `parents` support in query.
27052705 * @since 6.7.0 Added support for the `format` property in query.
27062706 * @since 7.0.0 Updated `taxQuery` structure.
2707+ * @since 7.1.0 Added support for the `excludeCurrent` property in query.
27072708 *
27082709 * @param WP_Block $block Block instance.
27092710 * @param int $page Current query's page.
@@ -2749,6 +2750,12 @@ function build_query_vars_from_query_block( $block, $page ) {
27492750 $ excluded_post_ids = array_filter ( $ excluded_post_ids );
27502751 $ query ['post__not_in ' ] = array_merge ( $ query ['post__not_in ' ], $ excluded_post_ids );
27512752 }
2753+ if ( ! empty ( $ block ->context ['query ' ]['excludeCurrent ' ] ) ) {
2754+ $ current_post_id = get_the_ID ();
2755+ if ( $ current_post_id ) {
2756+ $ query ['post__not_in ' ][] = $ current_post_id ;
2757+ }
2758+ }
27522759 if (
27532760 isset ( $ block ->context ['query ' ]['perPage ' ] ) &&
27542761 is_numeric ( $ block ->context ['query ' ]['perPage ' ] )
Original file line number Diff line number Diff line change @@ -12,10 +12,8 @@ class Tests_Blocks_wpBlock extends WP_UnitTestCase {
1212
1313 /**
1414 * Fake block type registry.
15- *
16- * @var WP_Block_Type_Registry|null
1715 */
18- private $ registry = null ;
16+ private ? WP_Block_Type_Registry $ registry = null ;
1917
2018 /**
2119 * Set up each test method.
@@ -837,6 +835,36 @@ public function test_build_query_vars_from_query_block() {
837835 );
838836 }
839837
838+ /**
839+ * @ticket 65373
840+ */
841+ public function test_build_query_vars_from_query_block_exclude_current (): void {
842+ $ this ->registry ->register (
843+ 'core/example ' ,
844+ array ( 'uses_context ' => array ( 'query ' ) )
845+ );
846+
847+ global $ post ;
848+ $ post = self ::factory ()->post ->create_and_get ();
849+ $ this ->assertInstanceOf ( WP_Post::class, $ post );
850+
851+ $ parsed_blocks = parse_blocks ( '<!-- wp:example {"ok":true} -->a<!-- wp:example /-->b<!-- /wp:example --> ' );
852+ $ parsed_block = $ parsed_blocks [0 ];
853+ $ context = array (
854+ 'query ' => array (
855+ 'excludeCurrent ' => true ,
856+ ),
857+ );
858+ $ block = new WP_Block ( $ parsed_block , $ context , $ this ->registry );
859+ $ query = build_query_vars_from_query_block ( $ block , 1 );
860+
861+ $ this ->assertSame (
862+ array ( $ post ->ID ),
863+ $ query ['post__not_in ' ],
864+ 'The current post ID should be excluded via post__not_in. '
865+ );
866+ }
867+
840868 /**
841869 * @ticket 64416
842870 */
You can’t perform that action at this time.
0 commit comments