[wp-hackers] Adding query var to pages with rewrites

Tom Barrett tcbarrett at gmail.com
Wed Mar 14 15:36:41 UTC 2012


Hopefully I've figured it out:

add_action( 'init', 'tcb_add_rewrite_rules' );
function tcb_add_rewrite_rules(){
  add_rewrite_tag( '%tcb_item%', '([\d]+)' );
  add_rewrite_rule( '(.+?)/tcb_item/([0-9]+)/?',
'index.php?pagename=$matches[1]&tcb_item=$matches[2]', 'top' );
}


On 14 March 2012 14:04, Tom Barrett <tcbarrett at gmail.com> wrote:

> I want to write a shortcode that grabs a custom query var. For example:
> http://www.tcbarrett.com/contact-us/myvar/12
> This loads the /contact-us/ page and adds myvar=12
>
> I'm guessing this is much like the pagination (/contact-us/page/2), but
> I'm stuck on how to do this.
>
> --
> http://www.tcbarrett.com | http://gplus.to/tcbarrett |
> http://twitter.com/tcbarrett
>



-- 
http://www.tcbarrett.com | http://gplus.to/tcbarrett |
http://twitter.com/tcbarrett


More information about the wp-hackers mailing list