WordPress / gutenberg

The Block Editor project for WordPress and beyond. Plugin is available from the official repository.
https://wordpress.org/gutenberg/
Other
10.47k stars 4.18k forks source link

"Publicly Queryable" should not be necessary for post types to populate them in Editor #66283

Open stotzbalazs opened 1 day ago

stotzbalazs commented 1 day ago

Description

For some reason WordPress requires to have Publicly Queryable for post types to populate them in Editor. Why is this necessary? In many cases, post types that are not Publicly Queryable are not visible in the editor and cannot be used.

Is it possible to enable all post types without relating on Queryable?

Step-by-step reproduction instructions

I'm using

constpostTypes=useSelect(
(select) => select('core').getPostTypes({ per_page: -1 }), []
);

to get post types and that way i'm unable to populate post types in editor which are not "Publicly Queryable"

Screenshots, screen recording, code snippet

constpostTypes=useSelect(
(select) => select('core').getPostTypes({ per_page: -1 }), []
);

Environment info

No response

Please confirm that you have searched existing issues in the repo.

Please confirm that you have tested with all plugins deactivated except Gutenberg.

Mamaduka commented 17 hours ago

To make post types available via REST API, you need to set the show_in_rest param to true. The endpoint doesn't check the publicly_queryable value.

The getPostTypes selector just makes requests to the REST API endpoints; it doesn't do separate filtering.

Source: https://github.com/WordPress/wordpress-develop/blob/c6b30b6e18461d6f112c9eee11dd79fc991f3e53/src/wp-includes/rest-api/endpoints/class-wp-rest-post-types-controller.php#L113C36-L113C48

stotzbalazs commented 10 hours ago

Yes, but my problem is exactly related to this: the post types available via REST API, the show_in_rest param is set to true. However, the code snippet above only shows the given post type if it is set to publicly_queryable.

Mamaduka commented 9 hours ago

@stotzbalazs, can you share a post-type registration snippet for reproduction? I can't reproduce it locally using my test post types.

stotzbalazs commented 9 hours ago

I use ACF for post type creation, so it looks like this:

add_action( 'init', function() {
    register_post_type( 'committee', array(
    'labels' => array(
        'name' => 'Committees',
        'singular_name' => 'Committee',
        'menu_name' => 'Committee',
        'all_items' => 'All Committee',
        'edit_item' => 'Edit Committee',
        'view_item' => 'View Committee',
        'view_items' => 'View Committee',
        'add_new_item' => 'Add New Committee',
        'add_new' => 'Add New Committee',
        'new_item' => 'New Committee',
        'parent_item_colon' => 'Parent Committee:',
        'search_items' => 'Search Committee',
        'not_found' => 'No committee found',
        'not_found_in_trash' => 'No committee found in Trash',
        'archives' => 'Committee Archives',
        'attributes' => 'Committee Attributes',
        'insert_into_item' => 'Insert into committee',
        'uploaded_to_this_item' => 'Uploaded to this committee',
        'filter_items_list' => 'Filter committee list',
        'filter_by_date' => 'Filter committee by date',
        'items_list_navigation' => 'Committee list navigation',
        'items_list' => 'Committee list',
        'item_published' => 'Committee published.',
        'item_published_privately' => 'Committee published privately.',
        'item_reverted_to_draft' => 'Committee reverted to draft.',
        'item_scheduled' => 'Committee scheduled.',
        'item_updated' => 'Committee updated.',
        'item_link' => 'Committee Link',
        'item_link_description' => 'A link to a committee.',
    ),
    'public' => true,
    'publicly_queryable' => false,
    'show_in_rest' => true,
    'menu_icon' => 'dashicons-businessman',
    'supports' => array(
        0 => 'title',
        1 => 'thumbnail',
        2 => 'custom-fields',
    ),
    'taxonomies' => array(
        0 => 'committee-type',
        1 => 'local-network',
    ),
    'delete_with_user' => false,
) );
} );
Mamaduka commented 9 hours ago

@stotzbalazs, I get the same results. The "Committees" post type is returned by the selector.

Screenshot

Image