Describe the bug
I am developing Gutenberg Plugins I found a problem. if there are more than 10 post types, it only shows me the first 10.
It's not related with "show_in_rest"
Probably it's related with: _context.abrupt but i'm not sure
To reproduce
Use this
edit: withSelect((select) => {
const {getPostTypes} = select('core');
return {
types: getPostTypes()
};
}
Expected behavior
Return all post types
Here's the code in question: https://github.com/WordPress/gutenberg/blob/a8bc55089eaa5df32b5ed9c36b038ccb066d4062/packages/core-data/src/entities.js
Looks like there's no pagination for these API requests.
There's no pagination but still return 10 results.
If i use a similar/same code:
apiFetch({path: '/wp/v2/types?context=edit'}).then(function (data) {
console.log(data);
});
return all the results
I can't upload a fix because I don't know how to work with function* and yield. If anyone take care of it I appreciate it :)
Or if anyone know any workaround using getEntityRecord I appreciate it. It is a big block for my development :(
Did anyone found a workaround to this?
Did anyone found a workaround to this?
I came across this problem as well today. My pragmatic workaround for my development environment was to patch WordPress core.
I changed the get_collection_params method in wp-includes/class-wp-rest-post-types-controller.php to set per_page to -1
public function get_collection_params() {
return array(
'context' => $this->get_context_param( array( 'default' => 'view' ) ),
'per_page' => -1,
);
}
This allowed me to continue. I imagine it's easy enough to fix the client end to do this for both getPostTypes and taxonomies.
I imagine it's easy enough to fix the client end to do this for both getPostTypes
For Gutenberg source I changed packages/core-data/src/entities.js
In loadPostTypeEntities I added the per_page: -1 parameter.
const postTypes = yield apiFetch( { path: '/wp/v2/types?context=edit' , per_page: -1 } );
It now appears that all I needed to do was to add the per_page: 1 parameter to my call to getPostTypes.
const postTypes = select( 'core').getPostTypes( { per_page: -1 });
Hopefully, someone will have a look at these 3 comments and let us know what the right solution is.
Most helpful comment
It now appears that all I needed to do was to add the
per_page: 1parameter to my call to getPostTypes.Hopefully, someone will have a look at these 3 comments and let us know what the right solution is.