Make WordPress Core

Opened 8 years ago

Last modified 4 weeks ago

#44803 new feature request

Add a page to a menu by its ID or slug

Reported by: milerm Owned by:
Priority: normal Milestone: Awaiting Review
Component: Menus Version: 4.9.8
Severity: normal Keywords: has-patch has-unit-tests
Cc: Focuses:

Description

I'm "porting" a college's website from Joomla to WordPress.

Said website has +2000 pages, which span from ~2013 onwards. It's the biggest mess you can imagine. There are many repeated pages, repeated categories, empty categories and so on.

Building the main menu for this website has been a pain in the ass, too, because the "adding pages to a menu" in WordPress is meant for small websites:

For example, I was trying to add a page named "Evaluación docente". There are several pages called exactly the same, but typing "Evaluación docente", or "Evaluacion docente" (without accents), "evaluacion docente" or even ""Evaluación docente"" (with the quotes, hoping them would help to do a exact match search) returned other pages that weren't the one I was looking for - nor even the other "Evaluación docente" pages! Seems like a very fuzzy search. Sometimes you're lucky and you get the page you're looking for, but sometimes you don't.

So I think it would be wonderful if there were some sort of way to add a page to a menu by typing its id or its slug.

Change History (3)

#1 @SergeyBiryukov
8 years ago

  • Component General → Menus

#2 @audrasjb
8 years ago

  • Keywords needs-patch added

Hi, welcome to WordPress Trac and thank you for this ticket.

I think that feature would require to add new search input fields to separate search by Name, Slug or ID.

Said website has +2000 pages, which span from ~2013 onwards. It's the biggest mess you can imagine. There are many repeated pages, repeated categories, empty categories and so on.

I'm not sure we are going to add that new feature for the moment. In your case, maybe your best bet would be to start with the beginning: remove/merge duplicates page and categories first?

Last edited 8 years ago by audrasjb (previous) (diff)

This ticket was mentioned in ​PR #14193 on ​WordPress/wordpress-develop by ​@akshat2802.


4 weeks ago
#3

  • Keywords has-patch has-unit-tests added; needs-patch removed

Adds exact slug matching to every "Add Items" search surface in the nav menu editor (classic Menus screen, its no-JS fallback, and the Customizer's menu panel), merged ahead of the existing fuzzy title search.

Problem

On large sites with many pages — the reporting use case is a Joomla-to-WordPress migration with 2000+ pages — the "Add Pages" quick search is a fuzzy title search and cannot disambiguate pages that share the exact same title. No search strategy based on titles can fix that; only an identifier orthogonal to the title (the slug) can. There was previously no way to add a menu item by slug (or ID) at all.

A related ticket, #48655 (WP 6.9), already restricted the classic screen's AJAX search to post_title only instead of title+excerpt+content, which cut down on irrelevant matches from body content — but it doesn't help when two pages are *titled identically*, and it only touched one of three independent search code paths in core.

What this changes

Every search box now checks the query against the post/term slug (exact match, =, not LIKE) in addition to the existing fuzzy title search, with no new UI and no prefix syntax — the same input field is reused. An exact slug match, when found, is always ranked first and deduplicated against the fuzzy results, and takes a slot within the existing result caps rather than being added on top of them.

  • src/wp-admin/includes/nav-menu.php
    • _wp_ajax_menu_quick_search() — exact slug lookup for both the quick-search-posttype-* and quick-search-taxonomy-* AJAX branches, via get_page_by_path() / get_terms( [ 'slug' => ... ] ).
    • wp_nav_menu_item_post_type_meta_box() / wp_nav_menu_item_taxonomy_meta_box() — same lookup added to the no-JS fallback forms, which previously had no slug support and no restriction to title-only search at all.
  • src/wp-includes/class-wp-customize-nav-menus.php
    • WP_Customize_Nav_Menus::search_available_items_query() — same lookup added to the Customizer's "Add Items" panel. Pagination required care here: the client JS infers "more pages exist" purely from result count, and page 2+'s offset is precomputed from the original page size, so the fix fetches fuzzy results unchanged and trims the tail after merging, rather than shrinking the query limit (which would have desynced the offset math).
  • Exact match only, deliberately — no partial/LIKE slug matching, which would just recreate the same disambiguation problem on sites that already use systematic slug prefixes.
  • No post ID lookup. Decided against it: nobody memorizes a page's numeric ID, so it wouldn't actually solve the reported problem, and it would add numeric-string ambiguity (is 42 an ID or a slug?) for no real benefit.
  • No new filter — the existing wp_ajax_menu_quick_search_args filter is untouched, since the exact-match lookup is a separate call from the filtered WP_Query args.

Use of AI Tools

Note: See TracTickets for help on using tickets.