WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How can I get the post id from a permalink like "http://localhost/wordpress/animals/cat" in functions.php, I have tried url_to_postid() and get_page_by_path() but none seem to work.

share|improve this question
Is "animals" a custom post type? – MikeSchinkel Feb 17 '11 at 17:26
yes it is a custom post type – Tirithen Feb 17 '11 at 17:39
As wordpress can visit that url, it obviously knows how to do the permalinks to post id conversion, I need to do this as a function so that I can get the id other pages than the one I'm currently visiting. – Tirithen Feb 17 '11 at 17:45
up vote 1 down vote accepted

Hi @Tirithen:

Have you tried (which assumes your custom post type is 'animal' and not 'animals'):

$post = get_page_by_path('cat',OBJECT,'animal'); 
share|improve this answer
Yes, it's working fine now, I did not understand the syntax before. Thanks :-) – Tirithen Feb 17 '11 at 18:12
@Tirithen - Glad I could help! – MikeSchinkel Feb 17 '11 at 18:21

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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