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.)

  • Was this Helpful ?
  • yes   no

2 thoughts on “WordPress function url_to_postid not working with Anspress”

  1. i had the exact same issue on my site with url_to_postid, spent several hours trying to fix it. Your solution here works flawlessly for me. Thank you!

Leave a Reply

Your email address will not be published. Required fields are marked *