[wp-hackers] some problem with understanding wp_rewrite

Ozh ozh at ozh.org
Thu Oct 13 12:18:31 UTC 2011


I think what you need is a nice illustration of custom endpoints
See http://codex.wordpress.org/Rewrite_API/add_rewrite_endpoint

That would be something like:

// Add the endpoint rewrite rules
add_filter( 'init', 'ozh_ep_add_rules' );
function ozh_ep_add_rules() {
    add_rewrite_endpoint( 'partner', EP_ALL ); // add endpoint on all 
pages
}

// Add permalink structure and flush on plugin activation
register_activation_hook( __FILE__, 'ozh_ep_activate' );
function ozh_ep_activate() {
    ozh_ep_add_rules();
    flush_rewrite_rules();
}

// Handle the partner id early
add_filter( 'template_redirect', 'ozh_ep_template_redirect' );
function ozh_ep_template_redirect() {
    $partner = get_query_var( 'partner' );
    // do something with $partner
    // ...
}

HTH

Ozh

-- 
http://ozh.org/ - @ozh on Twitter
WordPress plugins? I wrote a book! http://amzn.to/plugindevbook

> hello
> 
> I spent all last night reading codex and tutorials but i still don't
> understand how to do this.
> 
> I run online shop on wordpress and now i want to create affiliate
> program. I will tell to affiliate partners that if someone of them
> want to publish referral link on their website, then they have to take
> any link from my shops' website and add /partner/1234 at the and,
> where '1234' is id of partner
> 
> OK, but how to manage this in wordpress? How to register this rewrite
> rule that 'any webpage which has "/partner/(.*?)" at end should be
> redirected to  version without this (or even it can stay) and to
> query_vars[] will be added 'partner''?
> 
> "Any" means that partner can publish somewhere links like:
> example.com/partner/1234
> example.com/blog/hello-world/partner/1234
> example.com/archive/january/partner/1234
> example.com/static-page/partner/1234
> 
> and any other variations which i cant even imagine right now :)
> 
> -- 
> (en) regards / (pl) pozdrawiam
> Konrad Karpieszuk
> http://tradematik.pl wtyczka do WordPressa do tworzenia sklepów dla
> klientów z Polski
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers



More information about the wp-hackers mailing list