WordPress function url_to_postid not working with Anspress
With the Anspress theme/plugin, using the WordPress native function url_to_postid()
on a question permalink returns the page ID of the base page. For example,
url_to_postid( "www.website.com/questions/question/this-is-the-question");
would return the page ID of the /questions
page.
To get the WP question ID of this-is-the-question
, use the following:
get_page_by_path( "/this-is-the-question", "ARRAY_A", get_post_types() );
(using get_post_types()
instead of 'questions'
allows the call to work even with permalinks of non-question contents.)