Tell me more ×
WordPress Answers is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I had asked this question in a different way too, but no one replied there! I guess I should rephrase it here.
My custom post is 'company'. I'm trying to add a custom rewrite rule. When the 'url http://domain..com/company/company-title-slug/replies', is accessed, I want redirect to a custom template(applied to a page named 'replies') with all the comments for this custom post listed. If I add the comment id in the url like this 'url http://domain..com/company/company-title-slug/replies/23', I want to redirect to another page with a custom template applied for displaying a single comment.

This is what I did for accessing the url... 'http://domain.com/replies/reply_id', and it works fine.

add_rewrite_rule('^replies/(.*)?$','index.php?pagename=replies&reply_id=$matches[1]','top');

Please guide me in the proper direction, having a real hard time with the url rewrite stuff!

Thanks in advance!

share|improve this question

2 Answers

up vote 1 down vote accepted

I haven't tested it, but what about:

add_rewrite_rule('^company/(.+)/replies/(.*)?$','index.php?pagename=replies&reply_id=$matches[2]','top');
share|improve this answer

Using add_rewrite_rule only is not enough. It only adds a new rewrite rule to WP. But you need to register new query variable (in your situation, it's reply_id) and parse the request to catch that query variable.

Jan Fabry has posted a detailed sample for creating custom rewrite rule, I think it contains all you need.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.
{"cc_re__cc_re__cc_by_sa_3_0": ["f=\"http://area51.stackexchange.com\" title=\"proposing new sites in the Stack Exchange network\">Area 51</a></li>\r\n                        <li><a href=\"http://careers.stackoverflow.com\">Stack Overflow Careers</a></li>\r\n                    \r\n                </ol>\r\n            </td>\r\n    </tr>\r\n</table>\r\n                </div>\r\n            </div>\r\n\r\n            <div id=\"copyright\">\r\n                site design / logo &copy; 2013 stack exchange inc; \r\n                user contributions licensed under <a href=\"http://creativecommons.org/licenses/by-sa/3.0/\" rel=\"license\">cc-wiki</a> \r\n                with <a href=\"http://blog.stackoverflow.com/2009/06/attribution-required/\" rel=\"license\">attribution required</a>\r\n            </div>\r\n            <div id=\"footer-flair\">\r\n                <a href=\"http://creativecommons.org/licenses/by-sa/3.0/\" class=\"cc-wiki-link\"></a>\r\n            </div>\r\n            <div id=\"svnrev\">\r\n                rev 2013.5.22.696\r\n            </div>\r\n                <div id=\"additional-notices\">\r\n                    WordPress is a trademark ", "\r\n</table>\r\n                </div>\r\n            </div>\r\n\r\n            <div id=\"copyright\">\r\n                site design / logo &copy; 2013 stack exchange inc; \r\n                user contributions licensed under <a href=\"http://creativecommons.org/licenses/by-sa/3.0/\" rel=\"license\">cc-wiki</a> \r\n                with <a href=\"http://blog.stackoverflow.com/2009/06/attribution-required/\" rel=\"license\">attribution required</a>\r\n            </div>\r\n            <div id=\"footer-flair\">\r\n                <a href=\"http://creativecommons.org/licenses/by-sa/3.0/\" class=\"cc-wiki-link\"></a>\r\n            </div>\r\n            <div id=\"svnrev\">\r\n                rev 2013.5.22.696\r\n            </div>\r\n                <div id=\"additional-notices\">\r\n                    WordPress is a trademark of the WordPress Foundation, registered in the US and other countries. This site is not affiliated with the WordPress Foundation in any way.\r\n                </div>\r\n            \r\n        </div>\r\n    </div>\r\n    <noscript>\r\n        <div id=\"noscript-warning\">WordPress Answers works best with Jav"], "copyright__copyright__copyright": [" It only adds a new rewrite rule to WP. But you need to register new query variable (in your situation, it's reply_id) and parse the request to catch that query variable.\n\nJan Fabry has posted a detailed sample for creating custom rewrite rule, I think it contains all you need.\n\nshare|improve this answer\n\nYour Answer\n\n\u00a0\ndiscard\n\nBy posting your answer, you agree to the privacy policy and terms of service.\n\nNot the answer you're looking for? Browse other questions tagged or ask your own question."]}