Opened 14 years ago
Last modified 40 hours 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: | has-patch has-unit-tests |
| 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 (6)
Change History (25)
#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
@
13 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.
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?".
I left out other posts fields from the allowed list as they don't seem applicable. 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
@
11 years ago
- Keywords needs-patch added; has-patch removed
Needs an improved patch based on nacin's last one per his comment
#17
@
3 months 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
#18
@
4 days ago
Test Report
Description
❌ No working patch available as existing patches (20044.diff → 20044.5.diff are outdated)
Environment
- WordPress: 7.1-alpha-62161-src
- PHP: 8.2.28
- Server: nginx/1.27.5
- Database: mysqli (Server: 8.4.5 / Client: mysqlnd 8.2.28)
- Browser: Chrome 144.0.0.0
- OS: macOS
- Theme: Twenty Twenty 3.0
- MU Plugins: None activated
- Plugins:
- Test Reports 1.2.0
Actual Results
- ❌ Issue not resolved with the patch, and the issue is still present.
Steps to Reproduce
- Navigate to Pages → Add New and create a page with the title "Slug Search Test" and the slug slug-search-test.
- Publish the page.
- Go to Pages → All Pages and enter slug-search-test into the search box.
- Navigate to the site frontend and use the search widget to search for the same slug: slug-search-test.
- 🐞 Bug occurs.
Supplemental Artifacts
This ticket was mentioned in PR #11489 on WordPress/wordpress-develop by @anukasha.
40 hours ago
#19
- Keywords has-patch has-unit-tests added; needs-patch removed
My changes are as follows:
Extends the existing post_search_columns filter (since 6.2.0) to allow searching posts and pages by slug (post_name).
Opt-in only — not searched by default to avoid performance issues.
How to Test
- Create a post with title Taco and slug burrito, publish it.
- Search for burrito — no results (expected default behaviour)
- Add this to a mu-plugin: add_filter( 'post_search_columns', function( $cols ) {
$cols[] = 'post_name';
return $cols;
} );
- Search burrito again — Taco post appears.
Or via unit tests: npm run test:php -- --filter Tests_Query_SearchColumns
Trac ticket: https://core.trac.wordpress.org/ticket/20044
## Use of AI Tools

Adds the
page_namecolumn to query's search