0

Trying to be tricky here, I want to show a list of articles with their author and excerpt. I'm using a custom field and want the user to just be able to list the URLs on their own line and that's it.

Is there a way to look up the non-rewritten url based on the friendly one? Then just pull the article ID from there via regex?

To further clarify:

Say this is the URL http://www.site.com/2013/10/wearable-tech-trends-element14.html

Can I take it back (decode) to? http://www.site.com/?p=123

So I can grab the 123 and use that to find the author and excerpt.

2
  • Maybe is my poor english, but I understand nothing. Can you post an example?
    – gmazzap
    Commented Oct 8, 2013 at 16:04
  • ok, example in the post.
    – ok1ha
    Commented Oct 8, 2013 at 16:16

1 Answer 1

4

There is a function called url_to_postid

$id = url_to_postid( get_permalink(40) ); // $id will be 40

Actually (WP 3.6) it works only for standard posts and page, but with WP 3.7 it will also work for custom post types.

1
  • This is a good place to learn.. :) @AmalMurali
    – gmazzap
    Commented Oct 8, 2013 at 18:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.