Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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
1  
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

1 Answer 1

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

 
discard

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.