admin管理员组

文章数量:1122832

Two of my top-level Pages, and all of their children, are missing from the dropdown menu in the Block Editor for selecting a Parent Page.

There are no special characters in the titles or permalinks. All of my other Pages do show up in the dropdown menu. And in fact, these two missing top-level Pages are already parents to some of my other Pages. They used to appear in the dropdown, and the database still has their IDs saved. (I do not know when they stopped appearing in the dropdown.)

So for example, if I look in the database at a child Page, the post_parent is set to the correct parent ID. And when I view the child Page or its parent Page on the front end, in the hierarchical left navigation both the parent and all of its children are shown. But when I edit the child Page, it says Parent Page is (no parent).

I've already:

  • Checked REST API is enabled (querying the REST API pulls them up accurately)
  • Checked postmeta (they have the same postmeta as the working Pages)
  • Checked taxonomies (no taxonomies assigned to these Pages, or to working Pages)
  • Checked Yoast settings (they are not noindexed or nofollowed)
  • Deactivated all plugins
  • Switched to Twenty Twenty theme
  • Hard-refreshed the Editor each time
  • Deleted one of the Pages, re-created it with the same slug, and saw that the new Page appeared as a Parent Page in the dropdown

Two of my top-level Pages, and all of their children, are missing from the dropdown menu in the Block Editor for selecting a Parent Page.

There are no special characters in the titles or permalinks. All of my other Pages do show up in the dropdown menu. And in fact, these two missing top-level Pages are already parents to some of my other Pages. They used to appear in the dropdown, and the database still has their IDs saved. (I do not know when they stopped appearing in the dropdown.)

So for example, if I look in the database at a child Page, the post_parent is set to the correct parent ID. And when I view the child Page or its parent Page on the front end, in the hierarchical left navigation both the parent and all of its children are shown. But when I edit the child Page, it says Parent Page is (no parent).

I've already:

  • Checked REST API is enabled (querying the REST API pulls them up accurately)
  • Checked postmeta (they have the same postmeta as the working Pages)
  • Checked taxonomies (no taxonomies assigned to these Pages, or to working Pages)
  • Checked Yoast settings (they are not noindexed or nofollowed)
  • Deactivated all plugins
  • Switched to Twenty Twenty theme
  • Hard-refreshed the Editor each time
  • Deleted one of the Pages, re-created it with the same slug, and saw that the new Page appeared as a Parent Page in the dropdown
Share Improve this question edited Apr 1, 2020 at 21:13 WebElaine asked Apr 1, 2020 at 21:01 WebElaineWebElaine 9,6741 gold badge16 silver badges27 bronze badges 1
  • 1 Let us continue this discussion in chat. – Elex Commented Apr 2, 2020 at 15:13
Add a comment  | 

4 Answers 4

Reset to default 1

The REST API maximum pages query can be manually tweaked above the hardcoded limit of 100 items in WordPress 6.6.2 (en_US); with a file change to WordPress core (not recommended for Production, but very possible) and a 'rest_page_collection_params' filter.

[Important] The below solution is for educational purposes and those willing to accept responsibility for backing up and restoring (if required) the entire website.

[Warning] The below solution is not permanent. As soon as WordPress updates, it will undo the below modifications.

[Benefit] The below solution will allow you to get the job done (pick any existing parent page in the block editor drop down list). The page item limit will be raised from 100 to 9876 items. It can then be reverted by putting the original file back and removing the filter.

[Objective-1] When editing a page and displaying content of a 'Page List' block, display all pages and NOT be limited by the JSON 100 items hard-coded restriction.

For example: There are other child pages under the 'Page List' -> 'Parent' setting pointing to 'DataMates Foundation' page as the parent filter for the block ... but only 1 is showing in the 'Page List' block when editing the page.

These are all the child pages that should be showing; but as there is just over 100 pages, some are not included. See screenshot above.

[Objective-2] The 'Page List' block has a 'Parent' attribute that should show ALL pages in the dropdown list to be available for selection as a filter to be applied to the list of pages. Standard WordPress 6.6.2 behaviour is to list only up to 100 items maximum. For those of us with > 100 pages in our website ... this enforced REST->JSON behaviour is a technical limitation being enforced at the expense of actually allowing the blocks 'Parent' filter to be able to function properly. The 'Parent' dropdown should list all pages. Like this screenshot shows on the right-side.

[Source] Reviewing WordPress 6.6.2 en_US source code.

[Observation] Identified in wp-includes/js/dist/block-library.js line 39333.

const MAX_PAGE_COUNT = 100;

[Solution-Part-A] Modify content of the minified version of that file ... modify the wp-includes/js/dist/block-library.min.js file.

Hint: Minification swaps the MAX_PAGE_COUNT constant to be an inline value directly.

Line 39417:

per_page: MAX_PAGE_COUNT,
_fields: ['id', 'link', 'menu_order', 'parent', 'title', 'type'],

Search for Minified JS:

per_page:100,_fields:

Replace with Minified JS:

per_page:9876,_fields:

Hint: You will find this second search result, just a few dozen characters further along, after the above search result.

Line 39425:

pages?.length <= MAX_PAGE_COUNT

Search for Minified JS:

?.length<=100

Replace with Minified JS:

?.length<=9876

[Solution-Part-B] Add this to your themes function.php file.

function aFilterFor_rest_page_collection_params($params) {
    if (isset($params['per_page'])) {
        $params['per_page']['maximum'] = 9876;  // Default 100.
    }
    return $params;
}
add_filter('rest_page_collection_params', 'aFilterFor_rest_page_collection_params');

[Solution-Part-C] The new value, 9876 in the above example, needs to be the same value in the modified wp-includes/js/dist/block-library.min.js file (Solution-Part-A) and in the functions.php file (Solution-Part-B).

Otherwise, it will error and look like this.

[Solution-Part-D] The minified files are cached in the browser. The above solution did not show itself to be working until a new browser incognito window was used with a brand new WordPress login session. Then it worked; showing the 'Page List' block in edit mode listing up to 9876 items and also showing all items that do not normally return in the limited <=100 default behaviour.

[Success-1] The 'Page List' block is displaying all child pages (up to the new maximum of 9876 pages) when we are using the block editor when editing a page.

[Success-2] The 'Page List' blocks 'Parent' attribute dropdown list is now showing all pages in the list as an available option to be set as the 'Parent' for filtering the 'Page List' block content.

[Observation] The above solution forces the default block-library behaviour for requests from the frontend to ask for a bigger list of items and do it all at once; by increasing the request 'per_page' and the maximum, which is not ideal is a perfect world. The above solution is like a big bang, get it working solution, that is not leveraging the pagination behaviour (that ideal solution would require further tweaking, if at all possible under the WordPress 6.6.2 hardcoded limitations).

[Conclusion] The above solution walk-through helps you select any 'Parent' page from the dropdown list in the block editor. It is a messy tweak for advanced WordPress maintainers to use, until the WordPress core code no longer requires this kind of manual work-around for the REST API 100 item hardcoded limitation.

This solution is live and working in all my sites and only requires a few extra steps, to put it back in after a WordPress core upgrade. A small effort to get the block editors parent page dropdown list working again.

I had the same issue on a site that I have inherited developer duties for. I found that with the Classic Editor Plugin Disabled although parent pages were still missing from the dropdown - I was able to key them in to the attributes box (with the Classic Editor Plugin enabled - direct keyed entry was prevented) and they were findable and settable. Not a solution but a workaround via the wordpress dashboard rather than via mysql.

Also note pages must be published by default to show How can I set a draft page as parent without publishing?

The root problem, as Elex helped me discover, is that the REST API only queries for a maximum of 100 pages at a time. This site had several hundred pages, and so only 100 of them would show at a time in the dropdown.

Publishing a new page and adding it as the parent of the old children works because that means the new page ID is high enough to be included in the query for 100 pages. It grabs the 100 highest IDs.

I had the same issue using WP Bakery page builder. In WP Bakery, there is an option to 'disable the Gutenberg Editor'.

For some odd reason, when I disabled Gutenberg, all of the correct pages were correct and missing ones were visible in the 'Parent Pages' dropdown choices. I suspect this issue had something to do with Gutenberg Editor, and when disabled, seemed to resolve the issue.

本文标签: Some pages are missing from the Parent Page select in the Editor