I’m starting some research to add a new feature to my Yet Another Related Posts Plugin. The idea (briefly) is that if there are any cross-postings from one post to another, it obviously should be returned as a related post.
In order to do this, however, I must take all anchor href’s in the content, check if it’s in the blog’s path and, if so, lookup the post ID based on the post URL (most likely permalink, but not necessarily).
I started looking at the Query Overview and the various classes/methods it references. What I’ve learned is:
WP objects run all the redirect code:
parse_request() gets the appropriate vars based on the permalink structure;
build_query_string() builds the (surprise!) query string;
and you enter this into query_posts().
However, I would like to run this on an arbitrary URL, while parse_request() is hard-coded to the $_SERVER vars. Sure, I can copy this code and make my own version of WP with a generic parse_request() method, but I don’t want to have to update this code with every WP version in the future that may change the way these redirects are done.
Does anyone know a better way to take a URL and find the appropriate post? Of course, this needs to work with whatever permalink structure the user has defined, as this is a public plugin.
Any hints or ideas would be appreciated! Thank you in advance!