Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm making a plugin that loads a specific template depending on a certain query var being passed, in effect creating a page for the plugin on the front end, as outlined in this post:

Create a page without adding a page in the Database - the first answer by Brian Fegter

So if I head to mysite.com/foobar I can use my custom template. However, if I hook a function up to wp_head and print out the paged query_var, it always returns 0, regardless of the value in the url (mysite.com/foobar/page/2, or example).

Any thoughts as to why this is happening? Is there a better way for my plugin to create a new page on the front end?

Thanks in advance.

share|improve this question
add comment

1 Answer

up vote 0 down vote accepted

I resolved this myself. The problem being:

add_rewrite_rule('^foobar?','index.php?is_foobar_page=1','top');

Which prevents any other query_vars from being created. To resolve this, a slightly more complicated rewrite rule combo is set up:

add_rewrite_rule('^foobar?$','index.php?is_foobar_page=1','top');
add_rewrite_rule('foobar/page/([0-9]+)?$','index.php?is_foobar_page=1&paged=$matches[1]','top');

This takes into consideration the creation of the plugin's subpage 'foobar' and also allows for pagination within this page.

Hope this helps someone.

share|improve this answer
add comment

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.