-
Notifications
You must be signed in to change notification settings - Fork 654
GET resources by slug #642
Comments
One pretty big gotcha: Each of these resources with slugs also permit numbers in the name equivalent field, which means the router would need to explicitly distinguish between a supplied id and a supplied slug. |
The way I've been doing it is through a custom endpoint, but I toyed with the idea of using a non-valid slug character to signal the use of a slug. For example: |
I am hugely in favour of using filters on the collection for this, and using a route with the (unchangeable) ID in it. Slugs can change at any point, so I think they definitely make more sense as filter variables. For the same reason, I'm +1 on removing the old One issue here I think is that there's no equivalent filter for |
Good point. We could punt on formal adoption, offer some suggestions on how developers can easily implement such an endpoint, and then see if anyone gets bitten by it in production.
I was thinking we'd use |
I agree in the general case, but |
Hey guys, If anyone is interested, here's an angular service I wrote to get posts, custom post types and pages by name (as well as ui-router state to get it): https://gist.github.com/marketingpartnersau/930c58bd371b76f015a3 |
For querying by slugs, our pattern will be Related #924 |
Hmm... hitting |
Not implemented in |
Ah ok... what's the best solution at present? |
Use |
Yeah... /wp-json/posts?name=why-us - 10 most recent posts both stopped working after they used to work A-OK. Only since updating to 1.2. I'm not crazy, the page exists: https://www.dropbox.com/s/27ceykrau45de62/Screenshot%202015-04-02%2010.43.58.png?dl=0 |
Oh. Can you open a new issue then? Might be a bug specific to 1.2 |
Sure. I tried downgrading, uninstalling, reinstalling, turning all plugins off again and having the same problem As it turns out no filters are working - can you imagine any reason why?
Would really appreciate some help as it has been working fine. |
Any idea when the ?slug param will be introduced? just getting empty arrays still :( |
@baffleinc Are any other query parameters (like |
A pretty common need is to be able to get a post by a slug. What if would it look like if you could get any resource by id or slug?
Post
- Type would need to be indicated in the route, as posts of two different types can have the samepost_name
.Term
- Taxonomy would need to be indicated in the route, as two terms of different taxonomies can have the sameslug
.Comment
- No such thing as a comment slug.Meta
- Meta keys are sometimes unique. We can't rely on it.User
- User's slug is theuser_nicename
which can be relied upon to be unique (as it's used in author URLs) and has an index in the db.The text was updated successfully, but these errors were encountered: