Make WordPress Core


Ignore:
Timestamp:
02/04/2025 08:59:04 AM (21 months ago)
Author:
Mamaduka
Message:

Editor: Fix parents argument validation for Query block.

Allow passing zero (0) via the parents argument. It is a valid value for hierarchical post types, often used to display top-level items.

Props mamaduka, audrasjb, peterwilsoncc.
Fixes #62901.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/blocks/wpBlock.php

    r59116 r59761  
    716716
    717717        /**
     718         * @ticket 62901
     719         */
     720        public function test_build_query_vars_from_query_block_with_top_level_parent() {
     721                $this->registry->register(
     722                        'core/example',
     723                        array( 'uses_context' => array( 'query' ) )
     724                );
     725
     726                $parsed_blocks = parse_blocks( '<!-- wp:example {"ok":true} -->a<!-- wp:example /-->b<!-- /wp:example -->' );
     727                $parsed_block  = $parsed_blocks[0];
     728                $context       = array(
     729                        'query' => array(
     730                                'postType' => 'page',
     731                                'parents'  => array( 0 ),
     732                        ),
     733                );
     734                $block         = new WP_Block( $parsed_block, $context, $this->registry );
     735                $query         = build_query_vars_from_query_block( $block, 1 );
     736
     737                $this->assertSame(
     738                        array(
     739                                'post_type'       => 'page',
     740                                'order'           => 'DESC',
     741                                'orderby'         => 'date',
     742                                'post__not_in'    => array(),
     743                                'tax_query'       => array(),
     744                                'post_parent__in' => array( 0 ),
     745                        ),
     746                        $query
     747                );
     748        }
     749
     750        /**
    718751         * @ticket 56467
    719752         */
Note: See TracChangeset for help on using the changeset viewer.