最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Access post from post id in URL

programmeradmin1浏览0评论

I'm doing unit tests for my plugin, and in my unit test, I check some basic things such as posting a custom post type. My script can create new post, and I can retrieve the ID of the posted item (I'm redirected to an URL like /wp-admin/post.php?post=16&action=edit&message=6, so I can deduce that the new post has the ID 16).

From this ID, I'd like to check if the post is as it should be by accessing it via URL, with something like /?post=16, but I can't find a way to get directly to my new post using just the ID and without doing any PHP stuff.

Is that possible?

I'm doing unit tests for my plugin, and in my unit test, I check some basic things such as posting a custom post type. My script can create new post, and I can retrieve the ID of the posted item (I'm redirected to an URL like http://wordpress.loc/wp-admin/post.php?post=16&action=edit&message=6, so I can deduce that the new post has the ID 16).

From this ID, I'd like to check if the post is as it should be by accessing it via URL, with something like http://wordpress.loc/?post=16, but I can't find a way to get directly to my new post using just the ID and without doing any PHP stuff.

Is that possible?

Share Improve this question edited Apr 24, 2019 at 12:24 fuxia 107k39 gold badges255 silver badges459 bronze badges asked Apr 22, 2017 at 6:00 Alexandre GermainAlexandre Germain 5881 gold badge5 silver badges13 bronze badges 5
  • Use your ?your-custom-post-type=16 – Max Yudin Commented Apr 22, 2017 at 12:13
  • Nope, it returns a 404.... Maybe it would be easier to modify my function.php to do that – Alexandre Germain Commented Apr 22, 2017 at 13:23
  • 9 OK, try ?p=16. – Max Yudin Commented Apr 22, 2017 at 13:37
  • Ok ok you got it... Why an answer to such basic question is so hard to find? Spent more than half an hour googleing around... Anyway! Thanks! – Alexandre Germain Commented Apr 22, 2017 at 15:53
  • @AlexandreGermain "Thank you" shouldn't be part of question, answer or comment. That's why I removed that in my edit. Reference: meta.stackexchange/questions/2950/… – Abdul Rauf Commented Apr 24, 2019 at 5:05
Add a comment  | 

1 Answer 1

Reset to default 22

Post can be accessed using post id by passing it as page_id query param to index.php. e.g.

http://wordpress.loc/index.php?page_id=16

Or simply

http://wordpress.loc/?page_id=16

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论