Skip to content

Commit cc39590

Browse files
Page Attributes: Fix: Parent-Dropdown missing for custom post-type.
We here allowing unbound requests for pages because pages have a parent picker UI than needed unbound requests. Pages were not the only CPT's that allow choosing a parent post. This commits makes sure we allow unbound requests for all hierarchical post types.
1 parent 09db904 commit cc39590

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

lib/rest-api.php

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -487,14 +487,15 @@ function gutenberg_handle_early_callback_checks( $response, $handler, $request )
487487
*
488488
* @see https://core.trac.wordpress.org/ticket/43998
489489
*
490-
* @param array $query_params JSON Schema-formatted collection parameters.
491-
* @param string $post_type Post type being accessed.
490+
* @param array $query_params JSON Schema-formatted collection parameters.
491+
* @param WP_Post_Type $post_type Post type object being accessed.
492492
* @return array
493493
*/
494494
function gutenberg_filter_post_collection_parameters( $query_params, $post_type ) {
495-
$post_types = array( 'page', 'wp_block' );
496-
if ( in_array( $post_type->name, $post_types, true )
497-
&& isset( $query_params['per_page'] ) ) {
495+
if (
496+
isset( $query_params['per_page'] ) &&
497+
( $post_type->hierarchical || 'wp_block' === $post_type->name )
498+
) {
498499
// Change from '1' to '-1', which means unlimited.
499500
$query_params['per_page']['minimum'] = -1;
500501
// Default sanitize callback is 'absint', which won't work in our case.
@@ -513,8 +514,10 @@ function gutenberg_filter_post_collection_parameters( $query_params, $post_type
513514
* @return array
514515
*/
515516
function gutenberg_filter_post_query_arguments( $prepared_args, $request ) {
516-
$post_types = array( 'page', 'wp_block' );
517-
if ( in_array( $prepared_args['post_type'], $post_types, true ) ) {
517+
if (
518+
is_post_type_hierarchical( $prepared_args['post_type'] ) ||
519+
'wp_block' === $prepared_args['post_type']
520+
) {
518521
// Avoid triggering 'rest_post_invalid_page_number' error
519522
// which will need to be addressed in https://core.trac.wordpress.org/ticket/43998.
520523
if ( -1 === $prepared_args['posts_per_page'] ) {

0 commit comments

Comments
 (0)