Opened 14 years ago
Last modified 6 weeks ago
#20044 new enhancement
Enable search for pages by slug
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Milestone: | Priority: | normal | |
| Severity: | normal | Version: | 3.7 |
| Component: | Query | Keywords: | needs-patch |
| Focuses: | Cc: |
Description
Would be nice to be able to search a page by its slug. Might need to be a bit different depending on the permalink-strategy.
Steps to reproduce(with Post name-permalinks enabled):
- Create a new page with a specific slug
- Save page
- Search for the exact slug-name
Attachments (5)
Change History (22)
#2
@
13 years ago
- Keywords has-patch needs-testing added; needs-patch removed
20044.diff uses the page_name column with LIKE, just like the post title and content. Needs testing, preferably on a large dataset with query caching disabled, not entirely sure how this will hit performance.
#4
@
12 years ago
- Milestone changed from 3.7 to Future Release
#7394 necessitates this doesn't move forward yet.
#5
@
12 years ago
- Keywords needs-testing removed
- Milestone changed from Future Release to 3.9
- Version set to 3.7
20044.2.diff refreshes and adds Unit Tests.
#6
@
12 years ago
20044.3.diff implements this as a filter on query_search_fields, which is more flexible than just jamming post_name in there. Because at that point, why not also add post_excerpt? This puts the onus on the developer to make the right decision in regards to performance.
Added query/search.php to unit tests.
#8
@
12 years ago
I'd also like to see the filter simply be for post fields, so 'post_content', 'post_title', etc., rather than having an explicit table reference inside the filter.
#9
follow-up:
↓ 10
@
12 years ago
- Keywords needs-docs removed
20044.4.diff checks anything passed in the filter against an array of allowed search fields—post_title, post_content, post_name, and post_excerpt—and then sets up the query.
I left out other posts fields from the allowed list as they don't seem applicable. Docs added to the query_search_fields filter as well.
#10
in reply to:
↑ 9
@
12 years ago
- Keywords needs-testing added
- Severity changed from trivial to normal
Replying to jeremyfelt:
20044.4.diff checks anything passed in the filter against an array of allowed search fields—post_title, post_content, post_name, and post_excerpt—and then sets up the query.
I left out other posts fields from the allowed list as they don't seem applicable.
Just to be clear, the filter in 20044.4.diff effectively expands the available search fields to also include post_excerpt and post_name *only*. Does it not limit the usefulness of the filter to say, "You can customize the search fields, but are limited to choosing within this list of four?".
Docs added to the
query_search_fieldsfilter as well.
Very nice :)
#12
@
12 years ago
I managed to not commit the original tests from #7394, which was to have added tests/query/search.php.
post_content_filtered should also be made available.
#13
@
12 years ago
- Keywords punt added
20044.5.diff cleans things up a bit.
That said, this doesn't help with ordering. In fact, #7394 kind of gets in the way here (it was fixed after this ticket was opened). You could add more fields to search, or even remove some, but it doesn't affect the ordering — a perfect post_name match ends up on the final page of results. That's not a great experience. Some earlier patches on #7394 allowed for the reverse: it helped with ordering but not with which fields were searched. Seems like we should add both tools at once.
#16
@
10 years ago
- Keywords needs-patch added; has-patch removed
Needs an improved patch based on nacin's last one per his comment
#17
@
6 weeks ago
- Keywords needs-testing removed
Test Report
Patch tested:
❌ No working patch available (existing patches 20044.diff → 20044.5.diff are outdated and do not apply cleanly)
Steps to Reproduce / Test
Screencast: https://files.catbox.moe/qzoif8.mp4
Dashboard (Admin Search)
- Navigate to Pages → Add New.
- Create a new page with:
- Title:
Slug Search Test - Slug:
slug-search-test
- Publish the page.
- Go to Pages → All Pages.
- Search for
slug-search-testusing the search box.
Frontend Search
- Open the site frontend.
- Use the site search form.
- Search for
slug-search-test.
Expected Results
- Pages should be searchable by slug.
- Searching by exact slug should return the matching page.
- Behavior should be consistent in:
- Admin dashboard search
- Frontend search results
Environment
- WordPress: 7.0-alpha-61215-src
- PHP: 8.2.29
- Server: nginx/1.29.4
- Database: mysqli (Server: 8.4.7 / Client: mysqlnd 8.2.29)
- Browser: Chrome 143.0.0.0
- OS: macOS
- Theme: Twenty Twenty-One 2.7
- MU Plugins: None activated
- Plugins:
- Test Reports 1.2.1
Actual Results
Before applying any patch
- ❌ Searching by slug in Pages → All Pages returns no results.
- ❌ Searching by slug on the frontend returns no results.
- ✅ Searching by title or content works correctly.
After applying existing patches (20044.diff – 20044.5.diff)
- ❌ Patches are outdated (12+ years old).
- ❌ Patches do not apply cleanly on current WordPress.
- ❌ No improvement in search ordering or relevance.
Notes
- Issue is reproducible in current WordPress.
- Existing patches attached to the ticket are obsolete.
- A new patch is required
Adds the
page_namecolumn to query's search