Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Navigation block: unable to add CPT archive page as link #39644

Open
bradhogan opened this issue Mar 22, 2022 · 15 comments
Open

Navigation block: unable to add CPT archive page as link #39644

bradhogan opened this issue Mar 22, 2022 · 15 comments
Labels
[Block] Navigation Affects the Navigation Block [Type] Enhancement A suggestion for improvement.

Comments

@bradhogan
Copy link

Description

I have a "Courses" CPT and I'm unable to add this to a navigation block when simply search for "courses" as you can if you say want to add a Blog link (assuming that is your posts front page).

Step-by-step reproduction instructions

  1. Create CPT "courses"
  2. Edit Site
  3. Edit Header Template Part
  4. In Navigation Block, click + button and search for "courses"
  5. Nothing appears. If you search for other pages, it works fine. I can also see individual course pages "course lesson 1" for example, but not the courses archive.

Screenshots, screen recording, code snippet

Screen Shot 2022-03-22 at 10 26 27 AM

Environment info

  • WP 5.9.2
  • Gutenberg 12.8.1
  • Mac 12.2.1
  • Chrome 99.0.4844.74

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

Yes

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

Yes

@talldan
Copy link
Contributor

talldan commented Mar 23, 2022

@bradley2083 Would you be able to share the code you're using to register the CPT?

If you're using a plugin for that, then maybe don't worry so much.

@talldan talldan added [Status] Needs More Info Follow-up required in order to be actionable. [Block] Navigation Affects the Navigation Block labels Mar 23, 2022
@bradhogan
Copy link
Author

bradhogan commented Mar 23, 2022

No problem @talldan here it is...

function mytheme_create_cpts() {
 
    register_post_type( 'courses',
        array(
            'labels' => array(
                'name' => __( 'Courses' ),
                'singular_name' => __( 'Course' )
            ),
            'public' => true,
            'has_archive' => true,
            'rewrite' => array('slug' => 'courses'),
            'hierarchical' => true,
            'show_in_rest' => true,
            'menu_icon' => 'dashicons-screenoptions',
            'supports' => array(
	            'thumbnail',
	            'editor',
	            'title',
	            'excerpt',
	            'author',
	            'page-attributes',
	            'custom-fields'
            ),
 
        )
    );
    
    register_taxonomy(
        'coursecategories',
        'courses',
        array(
            'hierarchical' => true,
            'label' => 'Categories',
            'query_var' => true,
            'show_in_rest' => true,
            'rewrite' => array(
                'slug' => 'coursecategories',
                'with_front' => false
            )
        )
    );
    flush_rewrite_rules();
}
add_action( 'init', 'mytheme_create_cpts' );

@talldan talldan added Needs Testing Needs further testing to be confirmed. and removed [Status] Needs More Info Follow-up required in order to be actionable. labels Mar 23, 2022
@talldan
Copy link
Contributor

talldan commented Mar 23, 2022

Thanks, I'll give this a test a little later.

@talldan
Copy link
Contributor

talldan commented Mar 24, 2022

I gave it a test, and I see what's happening. As you mention you can add individual courses. The search system doesn't really support searching for a single custom post type, the same as searching for 'post' doesn't only show posts.

Something I'd recommend doing is adding item_link and item_link_description labels to your CPT. When you do that there will be a block variation for courses available in the main block library (here I've called it Course Link):
Screen Shot 2022-03-24 at 1 36 13 pm

Adding that variation of the block will limit the search to just courses. It's not the easiest system though, it's still a bit hard to insert blocks into the navigation block using the main block library as you need to have another Link block selected.

I think there needs to be a better way to filter the search results when adding a link normally.

@bradhogan
Copy link
Author

bradhogan commented Mar 24, 2022 via email

@talldan
Copy link
Contributor

talldan commented Mar 24, 2022

I see, sorry, for some reason I missed that it was the archive page you were looking for. Re-reading now, you did mention it, so my mistake 🤦

That is indeed something you can't do from the search. The only option is to add is as a a custom link.

I'll relabel this as an enhancement request as that might be worth supporting.

@talldan talldan added [Type] Enhancement A suggestion for improvement. and removed Needs Testing Needs further testing to be confirmed. labels Mar 24, 2022
@Humanify-nl
Copy link

Humanify-nl commented Apr 2, 2022

Custom post types are a cornerstone of WP. I'd be baffled if its not worth supporting.

Let me add here for your test, that adding it as a custom link breaks the 'is-current-page' 'is-current-menu-page' markers.
(they don't display when for example you linked a custom post type archive, and you are in the archive), it also doesn't work for 'any' custom link entered in the menu.

@AdsonCicilioti
Copy link

They deprecated the customized navigation area, which would allow the use of the legacy menu manager and proposed the navigation block that loses the ability to add CPT's, which, as already mentioned, is the foundation of WP.

I sincerely hope that Wordpress continues to evolve, but a block that still doesn't cover the basic capabilities of the Legacy Menu Manager is making it difficult.

The way will be to create a template for the CPT archives. With that it will appear in the insertion of menus?

@Humanify-nl
Copy link

I’m sure they will get it right. Navigation is one of the most important aspects of a website..

But right now we’re either forced to used it as is, or drop the FSE (baby with the bathwater). That is why I proposed this: #39857

@talldan
Copy link
Contributor

talldan commented Apr 4, 2022

They deprecated the customized navigation area, which would allow the use of the legacy menu manager and proposed the navigation block that loses the ability to add CPT's, which, as already mentioned, is the foundation of WP.

The ability to add CPTs isn't lost. You can still add CPTs.

Currently there isn't a way to add the CPT Archive in the way the old menu system supported, and that's what's being discussed here.

Please do make a seperate issue if you're having problems with links to individual CPTs.

@github-actions
Copy link

github-actions bot commented Oct 4, 2022

Hi,
This issue has gone 180 days without any activity. This means it is time for a check-in to make sure it is still relevant. If you are still experiencing this issue with the latest versions, you can help the project by responding to confirm the problem and by providing any updated reproduction steps.
Thanks for helping out.

@github-actions github-actions bot added the Needs Testing Needs further testing to be confirmed. label Oct 4, 2022
@AdsonCicilioti
Copy link

bump

@ndiego
Copy link
Member

ndiego commented Oct 11, 2022

This issue was reviewed in today's Editor Bug Scrub. We have been able to replicate using the latest versions of Gutenberg and WordPress.

@masteradhoc
Copy link
Contributor

+1 on this one, definately needed. just have to build custom links now for this.

@chuckpearson
Copy link

Have the same issue, need a fix

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Navigation Affects the Navigation Block [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

No branches or pull requests

7 participants