Open Hube2 opened 5 years ago
Hi @Hube2 and thank you for your report. Interesting statement, however, when I set my CPT to be 'public' => false
it does not show up in any way on the frontend. Even after setting has_archive
. Can you share the code that you're using to generate your CPT?
here is the php, i got it from CPTUI. I would have given you the JSON export but couldn't figure out how to get just the one post type and there's several on the site I'm building. It could also have something to do with the publicly_queryable
argument. I know it took some playing to get the archive to show and not the singles.
function cptui_register_my_cpts_package() {
/**
* Post Type: Packages.
*/
$labels = array(
'name' => 'Packages',
'singular_name' => 'Package',
'menu_name' => 'Packages',
'all_items' => 'All Packages',
'add_new' => 'Add New',
'add_new_item' => 'Add New Package',
'edit_item' => 'Edit Package',
'new_item' => 'New Package',
'view_item' => 'View Package',
'view_items' => 'View Packages',
'search_items' => 'Search Packages',
'not_found' => 'No Packages Found',
'not_found_in_trash' => 'No Packages Found in Trash',
'parent_item_colon' => 'Parant Package',
'archives' => 'Package Archive',
'insert_into_item' => 'Insert into Package',
'uploaded_to_this_item' => 'Uploaded to this Package',
'filter_items_list' => 'Filter Package List',
'items_list_navigation' => 'Package List Navigations',
'items_list' => 'Package List',
'attributes' => 'Package Attributes',
'name_admin_bar' => 'Package',
'parent_item_colon' => 'Parant Package',
);
$args = array(
'label' => 'Packages',
'labels' => $labels,
'description' => '',
'public' => false,
'publicly_queryable' => true,
'show_ui' => true,
'delete_with_user' => false,
'show_in_rest' => false,
'rest_base' => '',
'rest_controller_class' => 'WP_REST_Posts_Controller',
'has_archive' => true,
'show_in_menu' => true,
'show_in_nav_menus' => false,
'exclude_from_search' => true,
'capability_type' => 'post',
'map_meta_cap' => true,
'hierarchical' => false,
'rewrite' => array('slug' => 'packages', 'with_front' => false),
'query_var' => true,
'menu_position' => 62,
'menu_icon' => 'dashicons-tickets-alt',
'supports' => array('editor', 'thumbnail', 'excerpt', 'custom-fields', 'revisions', 'author', 'page-attributes')
);
register_post_type('package', $args);
}
add_action('init', 'cptui_register_my_cpts_package');
Ah yes, this seems to be the winning combination:
'has_archive' => true,
'public' => false,
'publicly_queryable' => true,
Not sure if it's something that will get implemented. Since it's kind of counter-intuitive I'm not going to label it as a bug, but rather as a feature request.
Yeah, it's a little out of the box and I figure it to be an edge case. I doubt a lot of people even know this can be done or would find a use for it. In my particular case, the client has a 3rd party site that these packages are purchased through so while they are listed on the site they all link out to the 3rd party site. Doing this removes the need to remove the singles from the site map and or 301 redirecting them all. But I suppose that the archive page is not being put into the sitemap for the same reason, however, that's not as much of an issue.
In the mean time I've implemented ACF options pages for this with fields for meta title and description and I'm using the available filters to inject these into the archive pages.
Thanks for any consideration on making this change.
~JH
I've found opposite case that CPT is listed in "Content Types", but shouldn't be. After merging #8446, I think that's possible to replace get_post_types with method _get_accessible_posttypes which should be little changed:
$args = array(
'public' => true,
'publicly_queryable' => true,
);
$post_types = get_post_types( $args, 'names', 'or' );
$post_types = array_filter( $post_types, 'is_post_type_viewable' );
I think that will be correct solution.
We are also experiencing this issue. We have a custom post type with public false so that permalinks are not created for the post pages with the CPT. However we still have an archive page for this post type because it is a list of awards and we display all of the awards using the archive.
Please allow all CPT to show in Yoast SEO settings, including non-public CPT. This is needed for rest API, and who doesn't need can easily disable showing Yoast in Search appearance CPT settings.
In our case, the sponsored option is missing from link editor on private CPTs. Is there an easy way to enable it on private CPTs?
Link editor popup for public CPTs:
Link editor popup for private CPTs:
Please give us a description of what happened.
A post type can have a setting for 'public' of false and have the setting of 'has_archive' set to true. This allows WP to display the archive page (archive-{$post-type}.php) while not showing single posts of the post type. This can be done for a post type where the individual posts should never be shown and they are only shown on the archive page.
Under this condition the post type does not appear under => SEO => Search Appearance => Content Types.
Please describe what you expected to happen and why.
I would expect that if WP can show an archive page (has_arcive = true) that SEO for this archive page can be edited irregardless of the public setting.
How can we reproduce this behavior?
Technical info
Used versions