Question

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.

Was it helpful?

Solution

Hi @Tirithen:

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

$post = get_page_by_path('cat',OBJECT,'animal'); 
Licensed under: CC-BY-SA with attribution
Not affiliated with wordpress.stackexchange
scroll top