Let's say I have a page
with the name sample-page
.
I can do this:
get_page_by_path('sample-page')
To get that page.
Now, let's say I want to get a post where the URL to that post is /post/8
.
If I do
get_page_by_path('post/8'); // with or without leading slash
I get back null
.
How do I retrieve the page/post for any given URL in WP?
Edit: here's a screenshot that might add some clarity to my issue
Given the frontend permalink URL is /post/33
, how do I take that string and do the opposite? How do I take /post/33
and get the post from that?