[Plugin: Posts 2 Posts] Adding More Arguments to Query Posts
-
I am trying to add a url rewrite rule that finds any posts that are connected to the current post. 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[1]", 'top');
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. Keeping it this way instead of via tags 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.
I would propose being able to pass in some other arguments into the query string. For example, instead of just an ID, maybe you pass in a post_type and a slug variable. To help be even more specific, you could also include a parent ID or parent slug. That would make a regex rewrite rule possible and scalable.
What do you think scribu?
- The topic ‘[Plugin: Posts 2 Posts] Adding More Arguments to Query Posts’ is closed to new replies.