0

I have a custom taxonomy, "Events". I want to add the object for this taxonomy type as a Menu item (Appearance > Menus).

I don't mean I want to add a term of Events. I mean the taxonomy itself.

For a post type (say, my custom post type "Viewpoints") it is possible to add this as a Menu item (in Appearance > Menus, just go to my post type on the left-hand side of the menu builder, open it up, go "View All" and choose the top-most item, "Viewpoint Archives")...

enter image description here

But, for a taxonomy archive, there is no equivalent "[Taxonomy] Archives", nothing to select...

enter image description here

I know I can add a Custom Link to any front-end destination. Indeed, my "Events" are all output on a theme page page-events.php. But this is not a real pointer to the taxonomy object.

Is this because WordPress knows no such thing as a taxonomy archive index page? My understanding is, that is not a thing. Hence, I wrote page-events.php as a page template, and the code content spits out the relevant queries to list the terms.

Does anyone know of a workaround?

I am considering adding an ACF field to the menu items, because ACF's "ACF Taxonomy Selector Field" add-on would allow me to point to the real taxonomy object.

1
  • When you say you want a pointer to the taxonomy object what do you mean? Are you referring to individual terms? If there is no taxonomy archive index page then what are you expecting to show in that menu? Pages on the frontend are either singular posts, or archives of posts, there's no such thing as an archive of terms or an archive of users
    – Tom J Nowell
    Commented Mar 14, 2020 at 21:34

1 Answer 1

0

Is this because WordPress knows no such thing as a taxonomy archive index page? My understanding is, that is not a thing. Hence, I wrote page-events.php as a page template, and the code content spits out the relevant queries to list the terms.

Yes. All frontend pages in WP are post queries. WP looks at the query to figure out which template to load, and the main loop displays the posts.

If the query is for a single post, then it's a singular query, e.g. a blog post, a page, etc. If multiple posts are shown, it's an archive.

As a result, WP has no concept of an archive of users, or an archive of terms. The reason you don't see the page for the taxonomy itself is because there isn't one. you can test this out by taking example.com/taxonomy/term and removing /term, you'll get a 404 or redirected elsewhere.

Likewise, if we look at how rewrite rules work, URLs match on to regular expressions, that turn the URL into a list of query variables for a WP_Query object. The entire URL parsing stack is built to fuel post queries.

Having said that, you could build such a page, but you would need to create a rewrite rule for each taxonomy root page, and add query variables, then look for those and load the template manually, it's not for the faint of heart. To add to that, these "virtual pages" won't show up in the menu creation UI.

Keep in mind that in the next year or two, the menu creation process is earmarked for significant change and overhaul as part of the full site editing project, especially with the recent introduction of nav menu blocks ( written in 2020 )

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.