I am trying to add a url rewrite rule that finds any posts that are connected to the current post (using Posts 2 Posts by scribu). It's tied into the WP Query object, so all I have to do is pass another variable "connected" => $post_id and it works. This is my rule that I am working with, but I don't have the post_id as a part of my url, so I can't get that via regex.
add_rewrite_rule("cleats/([^/]+)/news", "index.php?tag=\$matches", 'top');
What really needs to happen if this is going to work is that I need to get the id based on the post slug via get_posts, but that seems like overkill to happen on every single init. Am I going down the right path, or is this not worth it?
What I want to happen is show only related news articles. For instance, I have a Manchester United page (custom post type of club) at /clubs/manchester-united. I want /clubs/manchester-united/news to show a listing of blog articles that are connected to that post. The way I am storing that information is with Posts 2 Posts, linking posts directly to that custom post. That keeps me from having to doubly maintain a list of tags that exactly match the custom post types that I have.
Where the query string for returning tags is as simple as ?tag=manchester-united, it works a little differently in my case. What I need is ?connected=45, where 45 is the post->ID of manchester-united. The regex in the rewrite rule above returns the slug "manchester-united", but that isn't enough information for my query. What I need to do is get the post->ID based on the "manchester-united" slug.
Is that hopefully a little clearer?