I recently built a website were I needed to let user edit the custom post type archive page with elementor. So I decided to use page templates instead of archive pages, that way,I can build my pages with code (custom loop) and elementor (widgets).
But after navigating in my website, I spotted strange behaviours. I'm sorry I have many questions, but I think they are all related to the same topic : the cleanest way to build CPT with page.
1-For my page template :
If I type for example, an url with the name of my CPT,
http://localhost/mytheme/lessons (the former CPT archive url)
I'm redirected to the first post of that CPT
I didn't made any redirection rules so I don't understand.
For all my custom post type I use the same code, with
hierarchical=> false and
$args = array( 'label' => _x('Formation', 'text_domain'), 'description' => _x('Formations', 'text_domain'), 'labels' => $labels, 'supports' => array('title', 'editor', 'thumbnail', 'comments', 'revisions', 'custom-fields'), 'hierarchical' => false, 'public' => true, 'show_ui' => true, 'show_in_menu' => true, 'menu_position' => 5, 'menu_icon' => 'dashicons-admin-home', 'show_in_admin_bar' => true, 'show_in_nav_menus' => true, 'can_export' => true, 'has_archive' => false, 'exclude_from_search' => false, 'publicly_queryable' => true, 'query_var' => true, 'rewrite' => array( 'slug' => 'toutes-nos-formations' ), 'capability_type' => 'post', 'show_in_rest' =>'true' )
The strange thing is that for one of those CPTs, if I type the name of the archive page, I see a 404.
So Is there a way to completely disable CPT archive page system, so no one can access to those archive pages built by wordpress and I wouldn't have those strange behaviours ?
I have a custom post type for which I don't need single pages. They exist in backend because I 'm just displaying them in a grid, in a page template.
How can I do to entirely hide those single pages url ? because I dont want a user to see those page that are not styled at all.
- As I'm using custom page, I loose the normal wordpress navigation system (current-menu-item ) So when I'm in a single CPT, the custom page in the menu doesn't highlight. Is there a simple solution for that ?