WordPress.org

Ready to get started?Download WordPress

Forums

Looking up post ID's from URL's (1 post)

  1. Hello plugin builders + hackers,

    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:

    1. WP objects run all the redirect code:
    2. parse_request() gets the appropriate vars based on the permalink structure;
    3. build_query_string() builds the (surprise!) query string;
    4. 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!

    mitcho

Topic Closed

This topic has been closed to new replies.

About this Topic

  • RSS feed for this topic
  • Started 5 years ago by mitcho (Michael Yoshitaka Erlewine)
  • This topic is not resolved
  • WordPress version: 2.6