using slug instead of ID in admin edit post url

admin2025-01-08  3

In Admin, is there any way to use a slug instead of a post ID# within the URL that takes you to a post's edit screen.

So instead of:

.php?post=5562&action=edit

You would use something like:

.php?slug=home&action=edit

Or, since the database stores the slug in the column post-name:

.php?post-name=home&action=edit

Of course, neither of these actually works. Is there some existing method for doing this using Wordpress' built-in URL parameters?

If not, what sort of function could be used in my theme's functions.php file that would make this work?

In Admin, is there any way to use a slug instead of a post ID# within the URL that takes you to a post's edit screen.

So instead of:

http://example.com/wp-admin/post.php?post=5562&action=edit

You would use something like:

http://example.com/wp-admin/post.php?slug=home&action=edit

Or, since the database stores the slug in the column post-name:

http://example.com/wp-admin/post.php?post-name=home&action=edit

Of course, neither of these actually works. Is there some existing method for doing this using Wordpress' built-in URL parameters?

If not, what sort of function could be used in my theme's functions.php file that would make this work?

Share Improve this question edited Oct 30, 2017 at 6:29 Jacob Peattie 44k10 gold badges49 silver badges62 bronze badges asked Dec 17, 2014 at 18:53 cvccvc 392 bronze badges 8
  • 1 slugs aren't necessarily unique, so this would be prone to failure. why do you want to do this? what problem are you trying to solve? – Milo Commented Dec 17, 2014 at 19:01
  • That's interesting, because I thought slugs were unique. I've often encountered a situation where I unknowingly created a post with the same title, and the slug generated appended with a number like '-2'. Anyway, I have a quick link to edit my home page created using Admin Menu Editor, but I had to duplicate and revise it, making the duplicate into the home page. I deleted the old one and changed the slug for the new one to 'home' (like the old one had). Of course, now my quick link no longer works. I'd like a link that always goes to edit page for my 'home' page, no matter what the ID is. – cvc Commented Dec 17, 2014 at 19:06
  • 1 slugs only have to be unique within a post type on the same level of hierarchy. if you want something like you describe, direct your request to admin-post.php, do your lookup, and redirect to the normal admin url for that post. – Milo Commented Dec 17, 2014 at 19:13
  • 1 How would you handle post revisions? Also why would you want this? Users shouldn't notice the URLs in the admin panel, are you trying to manually construct edit urls? – Tom J Nowell Commented Dec 17, 2014 at 19:35
  • This may be a fringe case, Tom... – cvc Commented Dec 18, 2014 at 18:13
 |  Show 3 more comments

1 Answer 1

Reset to default 0

If the home page is set as "Home" in settings, use:

get_edit_post_link( get_option( 'page_on_front' ) );
转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1736268592a1287.html

最新回复(0)